MCQ and Answer Key on Python Programming (Set 1)
1. Which type of Programming does Python support?
a) object-oriented programming
b) structured programming
c) functional programming
d) all of the mentioned
2. Is Python case sensitive when dealing with identifiers?
a) no
b) yes
c) machine dependent
d) none of the mentioned
3) Which of the following is used to define a block of code in Python language?
a) Indentation
b) Key
c) Brackets
d) All of the mentioned
4) What is the maximum possible length of an identifier?
a) 31 characters
b) 63 characters
c) 79 characters
d) none of the mentioned
5) find output :
_a = 10
print(_a, end="")
__b = 20
print(__b,end="")
__c__ = 30
print(__c__, end="")
a) 10,20,30
b) 10 20 30
c) 102030
d) none
6) Which of the following is an invalid variable?
a) my_string_1
b) 1st_string
c) foo
d) _
7) Why are local variable names beginning with an underscore discouraged?
a) they are used to indicate a private variables of a class
b) they confuse the interpreter
c) they are used to indicate global variables
d) they slow down execution
8) 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
9) Which of the following words cannot be a variable in python language?
a. _val
b. val
c. try
d. _try_
10) 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
11. 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
12. find output: print(round(4.576))
a) 4
b) 5
c) 4.5
d) 4.6
13. find output :
x,y,z = 2,4,6
pow(x,y,z)
a. 1,67,77,216
b. 4
c. 96
d. None
14. Find return value of the below mentioned function
all([2,4,0,6])
a. 2
b. 4
c. 0
d. 6
e. True
f. False
15. Find Output:
x=1
while True:
if x % 5 == 0:
break
print(x)
x += 1
a. error
b. 2 1
c. 0 3 1
d. None of these
16. Find output:
print(2**(3**2), end=",")
print((2**3)**2,end=",")
print(2**3**2)
a) 512, 64, 512
b) 512, 512, 512
c) 64, 512, 64
d) 64, 64, 64
17. Find Output:
print(min(max(False,-3,-4), 2,7))
a. -4
b. 2
c. False
d. None of the above
18. Find Output (if x = 6.237)
print("%.2f"%x)
a) 6.236
b) 6.23
c) 6.0000
d) 6.24
19. Find output:
len(["hello",2, '4', True, 8.4, complex(2,5)])
a) Error
b) 6
c) 4
d) 3
20. Find output:
x = 'abcd'
for i in x[1:3]:
print(i.upper(), end="")
a. ABCD
b. AB
c. BC
d. None of these
21. Find Output:
for i in [1, 2, 3, 4][::-2]:
print (i, end=" ")
a. 4 2 1
b. 4 3 2 1
c. 4 2
d. None of these
22. Find Output
def func(x):
x[0] = ['def']
x[1] = ['abc']
return id(x)
q = ['abc', 'def', 'xyz']
print(id(q) == func(q))
a) Error
b) None
c) False
d) True
23. Find output:
z=set('abc')
z.add('san')
z.update(set(['p', 'q']))
z
a) {‘a’, ‘c’, ‘c’, ‘p’, ‘q’, ‘s’, ‘a’, ‘n’}
b) {‘abc’, ‘p’, ‘q’, ‘san’}
c) {‘a’, ‘b’, ‘c’, ‘p’, ‘q’, ‘san’}
d) {‘a’, ‘b’, ‘c’, [‘p’, ‘q’], ‘san}
24. What arithmetic operators cannot be used with strings in Python?
a) *
b) –
c) +
d) All of the mentioned
25. Find output:
print("abc. DEF".capitalize())
a) Abc. def
b) abc. def
c) Abc. Def
d) ABC. DEF
26. Which of the following statements is used to create an empty set in Python?
a) ( )
b) [ ]
c) { }
d) set()
27. Find Output:
list1 = [1,2,3,4]
list2 = [2,4,5,6]
list3 = [2,6,7,8]
result = list()
result.extend(i for i in list1 if i not in (list2+list3) and i not in result)
result.extend(i for i in list2 if i not in (list1+list3) and i not in result)
result.extend(i for i in list3 if i not in (list1+list2) and i not in result)
result
a) [1, 3, 5, 7, 8]
b) [1, 7, 8]
c) [1, 2, 4, 7, 8]
d) error
28. Find Output:
list1 = [1, 3]
list2 = list1
list1[0] = 4
print(list2)
a) [1, 4]
b) [1, 3, 4]
c) [4, 3]
d) [1, 3]
29. Which of the following Python statements will result in the output: 6?
A = [[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
a) A[2][1]
b) A[1][2]
c) A[3][2]
d) A[2][3]
30. Find Output
i=0
while i < 5:
print(i, end=" ")
i += 1
if i == 3:
break
else:
print(0)
a) error
b) 0 1 2 0
c) 0 1 2
d) none of the mentioned
Answer Key
1 – d,
2 -b,
3 – a,
4-d,
5–c,
6 – b [Explanation: Variable names should not start with a number.] ,
7 – a [Explanation: indicates private variables of a class, not be accessed from outside
the class.]
8 – b [Explanation : no restriction in the length of variables]
9 – c [Explanation : try is a keyword]
10 – a [ Explanation : follow : PEMDAS]
11- b
12 - b
13 – b [Exp: pow(x,y,z)= (x**y) % z]
14 – f [Exp: The all () function returns True if all items in an iterable are true, otherwise it
returns False.]
15. None of these [Exp : 1234]
16 - a
17 - False [Exp. “False” is considered as value zero]
18 – d
19 – 6 [The function len() returns the length of the number of elements in the iterable.
Therefore the output of the function shown above is 6.]
20 – c
21 – c
22 – d
23 – c
24 – b
25 – a [Explanation: The first letter of the string is converted to uppercase and the others
are converted to lowercase]
26 – d
27 - a [Exp: in 1st extend the elements present in list1 , not in list 2 and 3 i.e., 1,3 in 2 nd
extend the elements present in list 2 but not in list 1 and 3 i.e., 5 and similarly in last
extends the elements present in list 3 but not in list 1 and 2 i.e., 7 and 8, therefore all
together : [1, 3, 5, 7, 8]]
28 – c
29 – b
30 – c