Learn Python MCQs

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

How do you create a lambda function in Python?

1) lambda x: x + 1

2) def lambda x: x + 1

3) lambda(x): x + 1

4) None of the above

Answer : lambda x: x + 1

What is the output of print("abc"[1])?

1) b

2) a

3) c

4) Error

Answer : b

How do you convert a list of strings to a list of integers in Python?

1) list(map(int, list))

2) list(map(string, int))

3) convert(list)

4) None of the above

Answer : list(map(int, list))

What is the output of print("Hello, World!".lower())?

1) hello, world!

2) Hello, world!

3) Error

4) HELLO, WORLD!

Answer : hello, world!

How do you create a new file in Python?

1) open("file.txt", "w")

2) open("file.txt", "r")

3) open("file.txt", "a")

4) None of the above

Answer : open("file.txt", "w")

What is the output of print("abc"[-1])?

1) c

2) Error

3) None

4) a

Answer : c

How do you define a class method in Python?

1) @classmethod def method(cls):

2) def method(cls):

3) @staticmethod def method(cls):

4) None of the above

Answer : @classmethod def method(cls):

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

1) 6.28

2) 6

3) Error

4) None

Answer : 6.28

How do you create a property in a class in Python?

1) @property def myProp(self):

2) def myProp(self):

3) myProp = property()

4) None of the above

Answer : @property def myProp(self):

What is the output of print("Hello".count("l"))?

1) 2

2) Error

3) None

4) 1

Answer : 2