Python MCQ and Answers – Part 12
This collection of Python Multiple Choice Questions and Answers (MCQs): Quizzes & Practice Tests with Answer.
1. What is the output of the following code?
>>>names = ['Alex', 'Bob', 'Yohan', 'Thomas'] >>>print(names[-1][-1])
A Alex
B Thomas
C s
D Error
2. What is the output of the following code?
x = [i**+1 for i in range(3)]; print(x);
A [1, 2, 5]
B [0, 1, 2]
C Error, ‘;’ is not authorised
D Error, **+ is not a valid operator
3. Is the following code valid?
>>>a=2,3,4,5 >>>a
A Yes, 2 is displayed
B No, too many values
C Yes, [2,3,4,5] is displayed
D Yes, (2,3,4,5) is displayed
4. Suppose that list1 is [1, 2, 3], so what is the output of list1 * 2
?
A [2, 4, 6]
B [1, 2, 3, 1, 2]
C [1, 2, 3, 1, 2, 3]
D [1, 2, 3, 3, 2, 1]
5. What is the output of the following code?
>>>x,y=1,2 >>>x,y=y,x >>>x,y
A (1,2)
B (2,1)
C Nothing is displayed
D Invalid Syntax
6. What is the output of the following code hex(14)
?
A 0xe
B 0Xe
C 0xE
D e
7. What is the output of the following code?
x={1:"X",2:"Y",3:"Z"} print(x.get(1,4))
A 1
B 4
C X
D Invalid Syntax
8. What is the output of the following code?
print((1, 2) + (3, 4))
A ((1, 2), (3, 4))
B (1, 2, 3, 4)
C (4, 6)
D Error!
9. To concatenate two strings in Python we use _______?
A . operator
B + operator
C ^ operator
D strcat() function
10. What is the output of the following code?
str = "{1}, {2} and {0}".format('Alex', 'Yohan', 'Bob') print(str)
A Alex, Yohan and Bob
B Yohan, Bob and Alex
C Alex, Yohan
D Yohan, Bob