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
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,
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
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