[docs] "+=" works not correct all the time

Wilfried Falk w_h_falk at yahoo.de
Sun Jan 15 18:09:41 CET 2012


Hello Python's,
 
"+="  does not work correct all the time.
 
Sometimes (but not allways)     identifier += 1     works as     print();  identifier = identifier + 1
 
Another misoperation of   "+="  you find in the code below:
 
def conc1(a, alist = []):
alist = alist + [a]
return alist
def conc2(b, blist = []):
blist += [b]
return blist
 
 
Main-Program
 
for i in range(4):
lista = conc1(i)
print(lista)
 
print()
for k in range(4):
listb = conc2(k)
print(listb)
 
The result of print(lista) is:
[0]
[1]
[2]
[3]
The result of print(listb) is:
[0]
[0, 1]
[0, 1, 2]
[0, 1, 2, 3]
 
 
Best regards
Wilfried
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/docs/attachments/20120115/f093be06/attachment.html>


More information about the docs mailing list