Learn Python MCQs

Prepare Python MCQs (Multiple choice Questions) for exam and job interviews.

What is the purpose of the __init__ method in a class?

1) Initialize object attributes

2) Define class methods

3) Create class variables

4) Terminate the class

Answer : Initialize object attributes

Which keyword is used to inherit a class in Python?

1) extends

2) inherits

3) super

4) class

Answer : class

What will be the output of print("A" in ["A", "B", "C"])?

1) True

2) False

3) None

4) 0

Answer : True

What is the correct way to create a set in Python?

1) mySet = {}

2) mySet = set()

3) mySet = []

4) mySet = ()

Answer : mySet = set()

How do you create a tuple in Python?

1) myTuple = ()

2) myTuple = []

3) myTuple = {}

4) myTuple = tuple()

Answer : myTuple = ()

Which of the following is not a valid variable name in Python?

1) myVar

2) my-var

3) my_var

4) myVar2

Answer : my-var

What is the purpose of the continue statement in a loop?

1) Skip the current iteration

2) Stop the loop

3) Exit the loop

4) Restart the loop

Answer : Skip the current iteration

What will be the output of print(type([]))?

1) <class 'list'>

2) <class 'dict'>

3) <class 'set'>

4) <class 'tuple'>

Answer : <class 'list'>

How do you define a default argument in a function?

1) def myFunc(arg1, arg2=default):

2) def myFunc(arg1, arg2):

3) def myFunc(arg1:default):

4) def myFunc(arg1=default):

Answer : def myFunc(arg1, arg2=default):

What is the output of print(range(5))?

1) 0 1 2 3 4

2) [0, 1, 2, 3, 4]

3) range(0, 5)

4) 0 1 2 3 4 5

Answer : range(0, 5)