0% found this document useful (0 votes)
2K views15 pages

Maximum Length of Python Identifiers

This document contains a question bank on Python programming with 47 multiple choice questions. The questions cover topics like Python identifiers, the creator of Python, file extensions, control flow, functions, classes, strings and more. Sample questions include the maximum length of an identifier, when Python 3.0 was developed, the use of indentation in Python, and built-in functions like print().

Uploaded by

Anuja Memane
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views15 pages

Maximum Length of Python Identifiers

This document contains a question bank on Python programming with 47 multiple choice questions. The questions cover topics like Python identifiers, the creator of Python, file extensions, control flow, functions, classes, strings and more. Sample questions include the maximum length of an identifier, when Python 3.0 was developed, the use of indentation in Python, and built-in functions like print().

Uploaded by

Anuja Memane
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

QUESTION BANK

PYTHON PROGRAMMING

1) What is the maximum possible length of an identifier?

a. 16
b. 32
c. C.64
d. [Link] of these above

2) Who developed the Python language?

a. Zim Den

b. Guido van Rossum

c. Niene Stom

d. Wick van Rossum

3) In which year python language developed?

a. 1995

b. 1972

c. 1981

d. 1989

4) In which language is Python written?

a. English

b. PHP

c. C

d. All of the above

5) Which one of the following is the correct extension of the Python file?

a. .py

b. .python
c. .p

d. None of these

6) In which year was the Python 3.0 version developed?

a. 2008

b. 2000

c. 2010

d. 2005

7) What do we use to define a block of code in Python language?

a. Key

b. Brackets

c. Indentation

d. None of these

8) Which character is used in Python to make a single line comment?

a. /

b. //

c. #

d. !

9) Which of the following statements is correct regarding the object-oriented


programming concept in Python?

a. Classes are real-world entities while objects are not real

b. Objects are real-world entities while classes are not real

c. Both objects and classes are real-world entities

d. All of the above

10) Which of the following statements is correct in this python code?

class Name:  
    def __init__(javatpoint):  
        javajavatpoint = java  
name1=Name("ABC")  
name2=name1  

a. It will throw the error as multiple references to the same object is not possible

b. id(name1) and id(name2) will have same value

c. Both name1 and name2 will have reference to two different objects of class
Name

d. All of the above

11) What is the method inside the class in python language?

a. Object

b. Function

c. Attribute

d. Argument

12) Which of the following declarations is incorrect?

a. _x = 2

b. __x = 3

c. __xyz__ = 5

d. None of these

Show Answer Workspace

13) Why does the name of local variables start with an underscore
discouraged?

a. To identify the variable

b. It confuses the interpreter

c. It indicates a private variable of a class

d. None of these

14) Which of the following is not a keyword in Python language?


a. val

b. raise

c. try

d. with

15) Which of the following statements is correct for variable names in Python
language?

a. All variable names must begin with an underscore.

b. Unlimited length

c. The variable name length is a maximum of 2.

d. All of the above

16) Which of the following declarations is incorrect in python language?

a. xyzp = 5,000,000

b. x y z p = 5000 6000 7000 8000

c. x,y,z,p = 5000, 6000, 7000, 8000

d. x_y_z_p = 5,000,000

17) Which of the following words cannot be a variable in python language?

a. _val

b. val

c. try

d. _try_

18) Which of the following operators is the correct option for power(ab)?

a. a ^ b

b. a**b

c. a ^ ^ b

d. a ^ * b

19) Which of the following precedence order is correct in Python?


a. Parentheses, Exponential, Multiplication, Division, Addition, Subtraction

b. Multiplication, Division, Addition, Subtraction, Parentheses, Exponential

c. Division, Multiplication, Addition, Subtraction, Parentheses, Exponential

d. Exponential, Parentheses, Multiplication, Division, Addition, Subtraction

20) Which one of the following has the same precedence level?

a. Division, Power, Multiplication, Addition and Subtraction

b. Division and Multiplication

c. Subtraction and Division

d. Power and Division

21) Which one of the following has the highest precedence in the expression?

a. Division

b. Subtraction

c. Power

d. Parentheses

22) Which of the following functions is a built-in function in python language?

a. val()

b. print()

c. print()

d. None of these

23) Study the following function:

round(4.576)  

What will be the output of this function?

a. 4

b. 5

c. 576

d. 5
24) Which of the following is correctly evaluated for this function?

pow(x,y,z)  

a. (x**y) / z

b. (x / y) * z

c. (x**y) % z

d. (x / y) / z

25) Study the following function:

all([2,4,0,6])  

What will be the output of this function?

a. False

b. True

c. 0

d. Invalid code

26) Study the following program:

x = 1  
while True:  
    if x % 5 = = 0:  
        break  
    print(x)   
    x + = 1  

What will be the output of this code?

a. error

b. 2 1

c. 0 3 1

d. None of these

27) Which one of the following syntaxes is the correct syntax to read from a
simple text file stored in ''d:\[Link]''?
a. Infile = open(''d:\\[Link]'', ''r'')

b. Infile = open(file=''d:\\\[Link]'', ''r'')

c. Infile = open(''d:\[Link]'',''r'')

d. Infile = [Link](''d:\\[Link]'',''r'')

Show Answer Workspace

28) Study the following code:

1. x = ['XX', 'YY']  
2. for i in a:  
3.     [Link]()  
4. print(a)  

What will be the output of this program?

a. ['XX', 'YY']

b. ['xx', 'yy']

c. [XX, yy]

d. None of these

Show Answer Workspace

29) Study the following function:

1. import math  
2. abs([Link](36))  

What will be the output of this code?

a. Error

b. -6

c. 6

d. 6.0

Show Answer Workspace
30) Study the following function:

1. any([5>8, 6>3, 3>1])  

What will be the output of this code?

a. False

b. Ture

c. Invalid code

d. None of these

Show Answer Workspace

31) Study the following statement:

1. >>>"a"+"bc"  

What will be the output of this statement?

a. a+bc

b. abc

c. a bc

d. a

Show Answer Workspace

32) Study the following code:

1. >>>"javatpoint"[5:]  

What will be the output of this code?

a. javatpoint

b. java

c. point
d. None of these

Show Answer Workspace

33) The output to execute string.ascii_letters can also be obtained from:?

a. character

b. ascii_lowercase_string.digits

c. lowercase_string.upercase

d. ascii_lowercase+string.ascii_upercase

34) Study the following statements:

>>> str1 = "javat"  
>>> str2 = ":"  
>>> str3 = "point"  
>>> str1[-1:]  

What will be the output of this statement?

a. t

b. j

c. point

d. java

35) Study the following code:

>>> print (r"\njavat\npoint")  

What will be the output of this statement?

a. Java point

b. java point

c. \njavat\npoint

d. Print the letter r and then javat and then point

36) Study the following statements:


>>> print(0xA + 0xB + 0xC)  

What will be the output of this statement?

a. 33

b. 63

c. 0xA + 0xB + 0xC

d. None of these

37) Study the following program:

class book:  
    def __init__(a, b):  
        a.o1 = b  
   
class child(book):  
    def __init__(a, b):  
        a.o2 = b  
   
obj = page(32)  
print "%d %d" % (obj.o1, obj.o2)  

Which of the following is the correct output of this program?

a. 32

b. 32 32

c. 32 None

d. Error is generated

38) Study the following program:

class Std_Name:   
    def __init__(self, Std_firstName, Std_Phn, Std_lastName):  
        self.Std_firstName = Std_firstName  
        self. Std_PhnStd_Phn = Std_Phn  
        self. Std_lastNameStd_lastName = Std_lastName  
   
Std_firstName = "Wick"  
name = Std_Name(Std_firstName, 'F', "Bob")  
Std_firstName = "Ann"  
[Link] = "Nick"  
print(name.Std_firstName, name.Std_lastName)  

What will be the output of this statement?

a. Ann Bob

b. Ann Nick

c. Wick Bob

d. Wick Nick

39) Study the following statements:

>>> print(ord('h') - ord('z'))  

What will be the output of this statement?

a. 18

b. -18

c. 17

d. -17

40) Study the following program:

x = ['xy', 'yz']  
for i in a:  
    [Link]()  
print(a)  

Which of the following is correct output of this program?

a. ['xy', 'yz']

b. ['XY', 'YZ']

c. [None, None]
d. None of these

41) Study the following program:

i = 1:  
while True:  
    if i%3 == 0:  
        break  
1.     print(i)  

Which of the following is the correct output of this program?

a. 1 2 3

b. 3 2 1

c. 1 2

d. Invalid syntax

42) Study the following program:

a = 1  
while True:  
    if a % 7 = = 0:  
        break  
    print(a)  
    a += 1  

Which of the following is correct output of this program?

a. 1 2 3 4 5

b. 1 2 3 4 5 6

c. 1 2 3 4 5 6 7

d. Invalid syntax

43) Study the following program:

i = 0  
while i < 5:  
    print(i)  
    i += 1  
    if i == 3:  
        break  
else:  
    print(0)  

What will be the output of this statement?

a. 1 2 3

b. 0 1 2 3

c. 0 1 2

d. 3 2 1

44) Study the following program:

i = 0  
while i < 3:  
    print(i)  
    i += 1  
else:  
    print(0)  

What will be the output of this statement?

a. 0 1

b. 0 1 2

c. 0 1 2 0

d. 0 1 2 3

45) Study the following program:

z = "xyz"  
j = "j"  
while j in z:  
    print(j, end=" ")  
What will be the output of this statement?

a. xyz

b. No output

c. x y z

d. j j j j j j j..

46) Study the following program:

x = 'pqrs'  
for i in range(len(x)):  
    x[i].upper()  
print (x)  

Which of the following is the correct output of this program?

a. PQRS

b. pqrs

c. qrs

d. None of these

47) Study the following program:

d = {0: 'a', 1: 'b', 2: 'c'}  
for i in d:  
    print(i)  

What will be the output of this statement?

a. a b c

b. 0 1 2

c. 0 a   1 b   2 c

d. None of these above

48) Study the following program:

d = {0, 1, 2}  
for x in d:  
    print(x)  

What will be the output of this statement?

a. {0, 1, 2} {0, 1, 2} {0, 1, 2}

b. 0 1 2

c. Syntax_Error

d. None of these above

49) Which of the following option is not a core data type in the python

language?

a. Dictionary

b. Lists

c. Class

d. All of the above

50) What error will occur when you execute the following code?

MANGO = APPLE  

a. NameError

b. SyntaxError

c. TypeError

d. ValueError

Common questions

Powered by AI

Python allows identifiers to be of any length, which means that developers can create descriptive variable names that enhance code readability and maintainability. Long identifiers can convey more information about the variable's purpose, which can be invaluable in understanding complex codebases. However, excessively long identifiers could increase typing errors and impact the ease of code editing and viewing, necessitating a balance between descriptiveness and practicality .

Python's use of indentation for block definition rather than braces or parentheses was a deliberate choice to emphasize readability and minimalistic coding style. This enforces a clean and consistent visual structure that reduces errors associated with unmatched braces. The requirement for syntactically significant whitespace can initially pose a challenge in collaboration, where diverse editor setups might interpret whitespace differently, yet it ultimately fosters code consistency and legibility, enhancing maintainability .

Migrating from Python 2 to Python 3 poses challenges due to incompatible changes like print function modifications, integer division differences, and changes in the handling of Unicode. These necessitate code refactoring to ensure compatibility. Strategies to facilitate migration include using tools like '2to3' for automated code translation and 'six' library to write compatible code for both versions. Understanding and modifying codebase infrastructure, such as dependency updates and testing, are essential for a seamless transition .

In Python, indentation is crucial because it is used to define the block of code. Unlike languages like C or Java that use brackets to group statements, Python relies on indentation levels to identify blocks such as loops, function definitions, and conditions . This makes Python code structurally distinct and clean, although it can require more attention to whitespace compared to bracketed languages.

Python loops, including for and while, are essential for iterating over data. However, to optimize performance with large datasets, techniques such as list comprehensions and generator expressions can be employed to reduce time complexity. These approaches limit the overhead of creating intermediary structures and facilitate lazy evaluation. Moreover, leveraging built-in functions like map() and filter() can exploit C-level optimizations further, minimizing the loop overhead and enhancing performance .

Dynamic typing in Python means variables are not bound to a specific data type, which increases flexibility and speeds up development by eliminating the need for explicit type declarations. This leads to concise, readable code since type checks are handled at runtime. However, this can also impact performance due to overhead involved in dynamic type resolution, and might increase runtime errors if types are incorrectly assumed. Despite potential performance drawbacks, dynamic typing significantly enhances productivity and accessibility, particularly for rapid prototyping and scripting .

Python's file operation syntax, such as using open('file_path', 'mode'), illustrates its straightforward approach to handling files across platforms. The use of double backslashes to escape paths, or forward slashes, ensures compatibility with different operating systems like Windows and UNIX-based systems. This abstraction simplifies the programmer's job, as they can write platform-independent code that remains intuitive and easy to understand, strengthening Python's versatility and accessibility for beginners and experts alike .

In Python, a constructor is defined using the __init__() method, ensuring that any object of the class is initialized properly. When defining a constructor, it is crucial to use self to refer to instance attributes and avoid common errors such as mismatched arguments or incorrect attribute assignments. A typical mistake is failing to differentiate between local arguments and instance variables, potentially leading to attributes not being initialized as expected. Proper use of constructors results in robust, reusable objects that encapsulate both data and behavior effectively .

Built-in functions such as print(), round(), and pow() provide standard operations that simplify development by eliminating the need to implement common functions manually. They enhance efficiency by being well-optimized, offering consistent performance improvements over user-defined counterparts. These functions contribute to cleaner code, reducing errors and improving readability, as they follow Python's convention of providing high-level abstractions through a rich standard library .

In Python, object-oriented programming is a paradigm that uses "objects" to represent data and methods to manipulate that data. In OOP, classes define the blueprints for objects. A class is a construct that defines a type of object, including its properties (fields/attributes) and behaviors (methods). Real-world entities are simulated by creating 'objects' that are instances of classes, thus objects are the real-world entities in Python. This allows for encapsulation, inheritance, and polymorphism, enhancing code reusability and efficiency .

QUESTION BANK
                        PYTHON PROGRAMMING
1) What is the maximum pos
c.
.p
d. None of these
6) In which year was the Python 3.0 version developed?
a. 2008
b. 2000
c.
2010
d. 2005
7) What do we u
        javajavatpoint = java  
name1=Name("ABC")  
name2=name1  
a. It will throw the error as multiple references to the sa
a. val
b. raise
c.
try
d. with
15) Which of the following statements is correct for variable names in Python 
language?
a. Al
a. Parentheses, Exponential, Multiplication, Division, Addition, Subtraction
b. Multiplication, Division, Addition, Subtracti
24) Which of the following is correctly evaluated for this function?
pow(x,y,z)  
a. (x**y) / z
b. (x / y) * z
c.
(x**y) % z
a. Infile = open(''d:\\java.txt'', ''r'')
b. Infile = open(file=''d:\\\java.txt'', ''r'')
c.
Infile = open(''d:\java.txt'',''
30) Study the following function:
1.
any([5>8, 6>3, 3>1])  
What will be the output of this code?
a. False
b. Ture
c.
Invalid
d. None of these
Show Answer Workspace
33) The output to execute string.ascii_letters can also be obtained from:?
a. characte
>>> print(0xA + 0xB + 0xC)  
What will be the output of this statement?
a. 33
b. 63
c.
0xA + 0xB + 0xC
d. None of these
37) S

You might also like