Python Strings · Question 11 · Medium

A list of integers is passed to join(). What happens when this runs?

print("+".join([1, 2, 3]))
  1. 1+2+3
  2. 6
  3. 123
  4. TypeError
Answer and explanation

Answer: D. TypeError

Explanation: join() only accepts strings, so a list of integers raises TypeError. Converting first, as in "+".join(str(n) for n in [1, 2, 3]), gives 1+2+3.

Previous: split() is called once with a comma separator and once with no argument. What… · Next: Format specifiers are used inside two f-strings. What does this print?

Practise python strings

Try a fresh set of python strings questions with an explanation after every answer, free and without signing up: Python Strings practice. Or sit a full placement mock test.

More python strings questions

More python practice

Lists & Tuples · Dictionaries & Sets · Conditions & Loops · Functions & Scope · Comprehensions & Generators · Classes & Objects · Exceptions & Files · Built-ins & Standard Library

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge