1
l = [1, 2, 3]
s = set([2, 3, 4])
l += s
print(l)  # Prints [1, 2, 3, 2, 3, 4]. Why?!
l = l +s  # Raises TypeError (as expected)

What's going on? I would expect the attempt of adding a set to a list result in a TypeError. Why the difference between += and +?

Assaf Muller
  • 386
  • 3
  • 11

0 Answers0