It would appear that in Python, list += x
works for any iterable x
:
In [6]: l = []
In [7]: l += [1]
In [8]: l += (2, 3)
In [9]: l += xrange(5)
In [10]: l
Out[10]: [1, 2, 3, 0, 1, 2, 3, 4]
Is this behaviour documented anywhere?
To contrast this with list + x
, the latter only works if x
is also a list
. This is spelled out in the documentation.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…