free and nonlocal variables

2013-03-21 Thread bartolome . sintes
In Python 3, free variable and nonlocal variable are synonym terms? Or is there a difference, like a free variable is a variable that is not a local variable, then nonlocal variables and global variables are both free variables? Thanking you in advance, Bartolomé Sintes --

x += ... is not the same than x = x + ... if x is mutable

2013-03-20 Thread bartolome . sintes
Hi, I thought that x += ... was the same than x = x + ..., but today I have realized it is not true when operating with mutable objects. In Python 3.3 or 2.7 IDLE (Windows) compare: a = [3] b = a a = a + [1] b [3] and a = [3] b = a a += [1] b [3, 1] Is this behaviour explained in the

tuple of ids of integers or lists

2013-03-17 Thread bartolome . sintes
In Python 3.3 for Windows, every list gets a different id when it is created: id([3]) 46555784 id([3]) 47920192 id([4]) 46532048 But if I write a tuple asking for the ids of two lists, each list seems to get the same id: id([3]), id([4]) (43079000, 43079000) I was expecting a tuple with

Re: tuple of ids of integers or lists

2013-03-17 Thread bartolome . sintes
OK. Now I understand it. I was confused because when two list are created in two different lines, Python gives them different ids, but when the two lists are created in the same line (in a tuple) Python gives them the same id. It doesn't really matter as these lists are just created and