Python 3.9.6 (default, Aug 18 2021, 19:38:01)
[GCC 7.5.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> a = []
>>> a += b'1'
>>> a
[49]
>>> [] + b'1'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: can only concatenate list (not "bytes") to list
The first variant gets a list of ints, the second fails because bytes can not be concatenated to a list, which makes sense to me.
What causes the difference in behaviour? I am surprised just storing a result in a variable seems to cause this. Does the += operator not make use of the + operator?