Malla Reddy College of Engineering
Multi Choice Questions on Python MCQ ()
Department of AIML
1. What is the maximum possible length of an identifier?
a. 16
b. 32
c. 64
d. None of these above
Ans : D
2. Who developed the Python language?
a. Zim Den
b. Guido van Rossum
c. Niene Stom
d. Wick van Rossum
Ans: B
3. In which year was the Python language developed?
a. 1995
b. 1972
c. 1981
d. 1989
Ans: D
4. In which language is Python written?
a. English
b. PHP
c. C
d. All of the above
Ans : C
5. In which year was the Python 3.0 version developed?
a. 2008
b. 2000
c. 2010
d. 2005
Ans: A
6. What do we use to define a block of code in Python language?
a. Key
b. Brackets
c. Indentation
d. None of these
Ans: C
7. 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
Ans : B
8. 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
Ans : B
9. What is the method inside the class in python language?
a. Object
b. Function
c. Attribute
d. Argument
Ans: B
10.Which of the following declarations is incorrect?
a. _x = 2
b. __x = 3
c. __xyz__ = 5
d. None of these
Ans: D
11. 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
Ans: C
12. Which of the following is not a keyword in Python language?
a. val
b. raise
c. try
d. with
Ans : A
13. 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
Ans : B
14. 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
Ans : B
15. Which of the following words cannot be a variable in python
language?
a. _val
b. val
c. try
d. _try_
Ans : C
16. Which one of the following has the highest precedence in the expression?
a. Division
b. Subtraction
c. Power
d. Parentheses
ans :D
17. Which of the following is correctly evaluated for this function?
a. (x**y) / z
b. (x / y) * z
c. (x**y) % z
d. (x / y) / z
ANS :C
18. Study the following program:
1. x = 1
2. while True:
3. if x % 5 = = 0:
4. break
5. print(x)
6. x+=1
What will be the output of this code?
a. error
b. 2 1
c. 0 3 1
d. None of these
ANS :A
19. Which one of the following syntaxes is the correct syntax to read from a
simple text file stored in ''d:\java.txt''?
a. Infile = open(''d:\\java.txt'', ''r'')
b. Infile = open(file=''d:\\\java.txt'', ''r'')
c. Infile = open(''d:\java.txt'',''r'')
d. Infile = open.file(''d:\\java.txt'',''r'')
ANS :A
20. Study the following code:
x = ['XX', 'YY']
for i in a:
i.lower()
print(a)
What will be the output of this program?
a. ['XX', 'YY']
b. ['xx', 'yy']
c. [XX, yy]
d. None of these
ANS: A
21. Study the following function:
import math
abs(math.sqrt(36))
What will be the output of this code?
a. Error
b. -6
c. 6
d. 6.0
Ans: D
22. 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
Ans : B
23. 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
Ans: B
24. Study the following code:
>>>"javatpoint"[5:]
What will be the output of this code?
a. javatpoint
b. java
c. point
d. None of these
Ans: C
25. 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
Ans : D
26. Study the following code:
1. >>> 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
Ans : C
27. 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
Ans : A
28. 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
Ans : D
29. 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"
name.lastName = "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
Ans : D
30. 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
Ans : B