81. What is the output of print(3 * 'ab')?
- a) ababab
- b) 3ab
- c) ab3
- d) Error
Test your knowledge of Python with these interactive multiple-choice questions.
81. What is the output of print(3 * 'ab')?
82. Which method returns the index of the first occurrence of a value in a list?
['a','b'].index('b') returns 1.
83. What does the zip() function do?
list(zip([1,2], ['a','b'])) returns [(1,'a'), (2,'b')].
84. Which function returns the largest item in an iterable?
max([1,2,3]) returns 3.
85. What is the output of print('Python'[-1])?
86. Which method splits a string at occurrences of a separator?
'a,b'.split(',') returns ['a','b'].
87. What is the output of print(bool([]))?
88. Which method returns a copy of a list in reverse order?
list(reversed([1,2])) returns [2,1] (doesn't modify original).
89. What does the any() function do?
any([False, 0, 'a']) returns True.
90. Which method converts a list to a string with elements separated by commas?
','.join(['a','b']) returns 'a,b'.
91. What is the output of print('Python'.islower())?
92. Which method removes and returns the last item of a list?
my_list.pop() removes and returns the last item.
93. What is the output of print('Python'[1:4])?
94. Which function returns a sequence of numbers?
range(3) generates 0,1,2.
95. What does the enumerate() function do?
list(enumerate(['a'])) returns [(0,'a')].
96. Which method returns a list of dictionary keys?
my_dict.keys() returns a view of all keys.
97. What is the output of print('Python'.endswith('on'))?
98. Which method removes whitespace from both ends of a string?
' hello '.strip() returns 'hello'.
99. What is the output of print('Python'[::2])?
100. Which function returns the smallest item in an iterable?
min([1,2,3]) returns 1.