Help understanding list operatoins inside functions in python 3

Joel Goldstick joel.goldstick at gmail.com
Tue Jan 13 08:39:46 EST 2015


On Tue, Jan 13, 2015 at 7:51 AM, <stephen.boulet at 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]
>

x in the outer scope is not x in the z() scope

> --
> https://mail.python.org/mailman/listinfo/python-list
>



-- 
Joel Goldstick
http://joelgoldstick.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20150113/3f3364ea/attachment.html>


More information about the Python-list mailing list