I have a list like this:
numlist = [1,2,3]
But, I know I can't do this: numlist += 1
.
Because it will raise a TypeError: 'int' object is not iterable
.
And I have to do numlist += 1,
So it will make a tuple.
But then why?:
>>> numlist = [1,2,3]
>>> numlist += 1,
>>> numlist
[1, 2, 3, 1]
Doesn't give errors.
My question
I did it with a variable, but if I do:
[1,2,3] + 1,
I get
TypeError: can only concatenate list (not "int") to list
Why if I do list + 1,
then errors but if I do variablecontainslist += 1,
then no errors?
And also,
[1,2,3] + (1,)
Gives
TypeError: can only concatenate list (not "tuple") to list