What is the result of 'ab' * 3 in Python?
-
A
'ababab'
Correct answer
-
B
TypeError
-
C
'aaabbb'
-
D
'ab3'
Correct answer
A. 'ababab'
21 views
Explanation
Multiplying a sequence by an integer repeats it. The same works for lists: [0] * 3 gives [0, 0, 0].
Reference
Asked in: NTS, PPSC, Python Developer Interviews
Doubts & discussion
Not sure why the answer is A? Ask here and get an explanation.
Ask a doubt about this MCQ