Raymond Hettinger added the comment:
Kapil, this behavior was intentional (not a bug), but later regarded as a
design mistake. GvR has said that if he had to do it over again list.__iadd__
would only accept other lists. The problem arises when people write "somelist
+= 'hello'" and expect
Karthikeyan Singaravelan added the comment:
https://docs.python.org/3/faq/programming.html#faq-augmented-assignment-tuple-error
> for lists, __iadd__ is equivalent to calling extend on the list and returning
> the list. That’s why we say that for lists, += is a “shorthand” for
> list.extend
Eric V. Smith added the comment:
For those not in front of a computer, the error is:
>>> l = l + 'de'
Traceback (most recent call last):
File "", line 1, in
TypeError: can only concatenate list (not "str") to list
--
nosy: +eric.smith
___
Python
New submission from Kapil Bansal :
Hi,
I tried addition and in-place addition on a list.
>>> l = ['a', 'b', 'c']
>>> l = l + 'de' (raises an error)
>>> l += 'de'
>>> print(l)
['a', 'b' , 'c', 'd', 'e']
I want to ask why the behaviour of both these are different?? If it is done
intentionall