ProgrammingModerateTCS NQT · Infosys
What does ','.join([1, 2]) do in Python 3?
- A. Returns '1,2'
- B. Raises TypeError because join needs str items
- C. Returns '[1, 3]'
- D. Returns '12'
Correct answer: B. Raises TypeError because join needs str items
str.join accepts only strings, so an int item raises a TypeError. Convert items with str() or map(str, ...) first.
More Python Programming questions
- Which statement about the heapq module is correct?
- What is printed? python print(sum(range(1, 10 5 + 1, 7)))
- What is printed? python print(pow(7, 222, 13), pow(7, 6, 13))
- What is printed? python print(max(map(len, ['ab', 'cde', 'f'])), sorted([[2, 1], [1, 5], [1, 2]]))
- What is printed? python print(list(enumerate('ab', start=5)))
- What is printed? python print(int(3.99999999999999999), int(-0.9))