Re: Help understanding list operatoins inside functions in python 3

2015-01-13 Thread mortoxa
On 01/13/15 23:51, stephen.bou...@gmail.com wrote: I'm a bit confused why in the second case x is not [1,2,3]: x = [] def y(): x.append(1) def z(): x = [1,2,3] y() print(x) z() print(x) Output: [1] [1] In your y() function, as you are appending data, the list must already exist

Re: Help understanding list operatoins inside functions in python 3

2015-01-13 Thread Laurent Pointal
Hello, stephen.bou...@gmail.com wrote: > I'm a bit confused why in the second case x is not [1,2,3]: > > x = [] > > def y(): > x.append(1) > > def z(): > x = [1,2,3] Here x is a local, so global x is not modified. If you want to modify gobal x, write: def z(): global x x = [1,

Re: Help understanding list operatoins inside functions in python 3

2015-01-13 Thread Joel Goldstick
On Tue, Jan 13, 2015 at 7:51 AM, wrote: > I'm a bit confused why in the second case x is not [1,2,3]: > > x = [] > > def y(): > x.append(1) > > def z(): > x = [1,2,3] > > y() > print(x) > z() > print(x) > > Output: > [1] > [1] > x in the outer scope is not x in the z() scope > -- > http

Help understanding list operatoins inside functions in python 3

2015-01-13 Thread stephen . boulet
I'm a bit confused why in the second case x is not [1,2,3]: x = [] def y(): x.append(1) def z(): x = [1,2,3] y() print(x) z() print(x) Output: [1] [1] -- https://mail.python.org/mailman/listinfo/python-list