MCQ

Python MCQ and Answers – Part 9

This collection of Python Multiple Choice Questions and Answers (MCQs): Quizzes & Practice Tests with Answer.
 

1. Which of the following is not a keyword in Python?

A eval

B assert

C nonlocal

D pass

A
 

2. All keywords in Python are ______

A uppercase

B lowercase

C capitalized

D None of the above

D
There are some in upper and lower case. Example:
Uppercase: False, True, None, etc…
Lowercase: if, for, pass, def, etc…
 

3. What is the output of the following code?
def sayHello(*name):
  print('Hello', name)

sayHello('Yohan', 'Thomas')

A Hello Yohan Hello Thomas

B Hello (‘Yohan’, ‘Thomas’)

C Hello Yohan

D Syntax error! sayHello() can only take one argument.

B
 

4. Which of the following statements is used to create an empty set?

A { }

B ( )

C [ ]

D set()

D
{} creates a dictionary, not a set. Only set() creates an empty set.
 

5. What is a recursive function?

A A function that calls all the functions of the program.

B A function that calls itself.

C A function that calls all the functions of the program except itself.

D There is no recursive function in Python.

B
 

6. What is the output of the following code?
res = lambda x: x * x
print(res(5))

A 5

B res(5)

C 25

D None

C
 

7. Which of the following cannot be declared as a variable?

A __init__

B in

C it

D on

B
“in” is a keyword.
 

8. What is the output of the following code when executed in Python shell?
>>> d = {1,2,3}
>>> d.intersection_update({2,3,4,5})
>>> d

A {2,3}

B {1,4,5}

C Error, duplicate element in the list

D Error, no method called intersection_update

A
The intersection_update method returns a set that contains the intersection of the two sets.
 

9. What is the output of the following code?
l = ['ab', 'cd']
for i in l:
    i.upper()
print(l)

A [‘AB’, ‘CD’]

B [‘ab’, ‘cd’]

C [None, None]

D None of the above

B
The upper() function does not modify the string. In this case, it returns a new string but we haven’t stored any.
 

10. What is the output of the following code?
True = False
while True:
    print(True)
    break

A False

B True

C None

D None of the above

D
SyntaxError, True is a reserved keyword and its value cannot be changed.
mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *