Learn Python MCQs
Prepare Python MCQs (Multiple choice Questions) for exam and job interviews.
What is the output of print(5 % 2)?
1) 1
2) 0
3) Error
4) 2
Answer : 1
How do you open a file in read mode in Python?
1) open("file.txt", "r")
2) open("file.txt", "w")
3) open("file.txt", "a")
4) None of the above
Answer : open("file.txt", "r")
What is the output of print(len({1, 2, 3}))?
1) 3
2) Error
3) None
4) 2
Answer : 3
How do you create a multi-line string in Python?
1) string = """Hello"""
2) string = "Hello"
3) string = [Hello]
4) None of the above
Answer : string = """Hello"""
What is the output of print(1, 2, 3, sep="-")?
1) 1-2-3
2) Error
3) None
4) 1 2 3
Answer : 1-2-3
How do you format a string in Python?
1) "{} {}".format(var1, var2)
2) "{} {}".join(var1, var2)
3) format(var1, var2)
4) None of the above
Answer : "{} {}".format(var1, var2)
What is the output of print(type(None) is None)?
1) True
2) False
3) Error
4) None
Answer : True
How do you check if a string is numeric in Python?
1) string.isnumeric()
2) string.isdigit()
3) Both a and b
4) None of the above
Answer : Both a and b
What is the output of print([x for x in range(5)])?
1) [0, 1, 2, 3, 4]
2) [1, 2, 3, 4, 5]
3) Error
4) [0, 1, 2, 3, 4, 5]
Answer : [0, 1, 2, 3, 4]
How do you create an empty set in Python?
1) set()
2) set([])
3) Both a and b
4) None of the above
Answer : Both a and b