Hello,
[email protected] 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,2,3]
You can read the Python FAQ about global/local rules:
https://docs.python.org/3/faq/programming.html#what-are-the-rules-for-local-and-global-variables-in-python
Or Dive Into Python
http://www.diveintopython.net/html_processing/locals_and_globals.html
(and for your problem, its the same with Python2 and Python3)
Or…
A+
Laurent.
--
https://mail.python.org/mailman/listinfo/python-list