Learn Python MCQs
Prepare Python MCQs (Multiple choice Questions) for exam and job interviews.
What is the output of print(5 == 5.0)?
1) True
2) False
3) None
4) Error
Answer : True
How do you create a class method in Python?
1) @classmethod def myMethod(cls):
2) @def myMethod(cls):
3) @class def myMethod(cls):
4) def myMethod(cls):
Answer : @classmethod def myMethod(cls):
What is the output of print(len([1, 2, 3]))?
1) 3
2) 2
3) 4
4) Error
Answer : 3
How do you sort a list in Python?
1) list.sort()
2) sort(list)
3) sorted(list)
4) Both a and c
Answer : Both a and c
Which of the following is a valid list comprehension in Python?
1) [x for x in range(5)]
2) [(x) for x in range(5)]
3) [] for x in range(5)
4) [x in range(5)]
Answer : [x for x in range(5)]
What does the len() function return for a dictionary?
1) The number of keys
2) The number of values
3) The total size
4) None of the above
Answer : The number of keys
What is the output of print("Python".find("y"))?
1) 1
2) 0
3) -1
4) 2
Answer : 1
Which method is used to convert a string to lowercase in Python?
1) lower()
2) toLower()
3) downcase()
4) lowercase()
Answer : lower()
What is the output of print(0 == False)?
1) True
2) False
3) None
4) Error
Answer : True
How do you create a new module in Python?
1) myModule.py
2) import myModule
3) module myModule
4) new myModule
Answer : myModule.py