Ethan Furman於 2012年1月14日星期六UTC+8上午2時40分47秒寫道: > Steven D'Aprano wrote: > > Normally this is harmless, but there is one interesting little glitch you > > can get: > > > >>>> t = ('a', [23]) > >>>> t[1] += [42] > > Traceback (most recent call last): > > File "<stdin>", line 1, in <module> > > TypeError: 'tuple' object does not support item assignment > >>>> t > > ('a', [23, 42]) > > > There is one other glitch, and possibly my only complaint: > > --> a = [1, 2, 3] > --> b = 'hello, world' > --> a = a + b > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > TypeError: can only concatenate list (not "str") to list > --> a += b > --> a > [1, 2, 3, 'h', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd'] > > IMO, either both + and += should succeed, or both should fail. > > ~Ethan~
The += operator is not only for value types in the above example. An operator of two operands and an operator of three operands of general object types are two different operators. -- http://mail.python.org/mailman/listinfo/python-list