Learn Python MCQs

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

How do you create a set in Python?

1) set()

2) set([])

3) Both a and b

4) None of the above

Answer : Option 1

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

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

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

3) Error

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

Answer : Option 1

How do you define a generator in Python?

1) def gen(): yield

2) def gen():

3) gen = (x for x in range(5))

4) None of the above

Answer : Option 1

How do you create a list in Python?

1) list = []

2) list = {}

3) list = ()

4) None of the above

Answer : Option 1

What is the output of print(type([]) == list)?

1) True

2) False

3) Error

4) None

Answer : Option 1

How do you create a string in Python?

1) string = ""

2) string = str()

3) Both a and b

4) None of the above

Answer : Option 1

What is the output of print(2 * 3 ** 2)?

1) 18

2) 12

3) Error

4) None

Answer : Option 1

How do you reverse a string in Python?

1) string[::-1]

2) reverse(string)

3) string.reverse()

4) None of the above

Answer : Option 1

What is the output of print(len([1, 2, 3]))?

1) 3

2) Error

3) None

4) 2

Answer : Option 1

How do you iterate over a list in Python?

1) for item in list:

2) for i in range(len(list)):

3) Both a and b

4) None of the above

Answer : Option 1