Learn Python MCQs
Prepare Python MCQs (Multiple choice Questions) for exam and job interviews.
How do you round a number in Python?
1) round(number)
2) number.round()
3) math.round(number)
4) None of the above
Answer : round(number)
What is the output of print(5 > 3 and 3 > 1)?
1) True
2) False
3) None
4) Error
Answer : True
How do you format a string in Python?
1) "{} {}".format(a, b)
2) f"{a} {b}"
3) Both a and b
4) None of the above
Answer : Both a and b
What is the output of print(3 * 0.1)?
1) 0.3
2) 0.30
3) 0.300
4) Error
Answer : 0.3
How do you create a context manager in Python?
1) with open("file.txt") as f:
2) open("file.txt")
3) None of the above
4) with open("file.txt"): as f:
Answer : with open("file.txt") as f:
What is the output of print("Hello".find("e"))?
1) 1
2) 2
3) 0
4) Error
Answer : 1
Which of the following is not a loop construct in Python?
1) for
2) while
3) do while
4) All of the above
Answer : do while
How do you create a zip object in Python?
1) zip(a, b)
2) zip(a b)
3) zip(a; b)
4) None of the above
Answer : zip(a, b)
What is the output of print("abc".find("z"))?
1) -1
2) Error
3) None
4) 2
Answer : -1
How do you read a file in Python?
1) open("file.txt").read()
2) read("file.txt")
3) open("file.txt").readlines()
4) None of the above
Answer : open("file.txt").read()