Learn Python MCQs
Prepare Python MCQs (Multiple choice Questions) for exam and job interviews.
What is the output of print(type(None))?
1) <class 'NoneType'>
2) <class 'null'>
3) <class 'None'>
4) <class 'undefined'>
Answer : <class 'NoneType'>
How do you create a tuple with a single element?
1) myTuple = (1,)
2) myTuple = (1)
3) myTuple = [1]
4) myTuple = {1}
Answer : myTuple = (1,)
What is the output of print("abc" * 2)?
1) abcabc
2) abc abc
3) abcabc
4) Error
Answer : abcabc
How do you create a new list from an existing one in Python?
1) newList = oldList.copy()
2) newList = oldList()
3) newList = oldList[:]
4) Both a and c
Answer : Both a and c
What will be the output of print(2 ** 3)?
1) 8
2) 9
3) 6
4) 4
Answer : 8
How do you check the data type of a variable in Python?
1) type(var)
2) check(var)
3) var.type()
4) isinstance(var)
Answer : type(var)
What is the output of print(1, 2, 3, sep="-")?
1) 1-2-3
2) 1,2,3
3) 1 2 3
4) 1- 2- 3
Answer : 1-2-3
Which of the following is a Python built-in function to convert an integer to a string?
1) str()
2) string()
3) toString()
4) intToString()
Answer : str()
What is the purpose of the self parameter in a class method?
1) Refers to the instance of the class
2) Refers to the class itself
3) Represents a global variable
4) None of the above
Answer : Refers to the instance of the class
How do you create an empty set in Python?
1) mySet = set()
2) mySet = {}
3) mySet = []
4) mySet = ()
Answer : mySet = set()