Argument-passing

Take a look at the following code. We declare a name, x, in the global scope, then we declare a function, func(y), and finally we call it, passing x:

# key.points.argument.passing.pyx = 3def func(y):    print(y)func(x)  # prints: 3

When func is called with x, within its local scope, a name, y, is created, and it's pointed to the same object x is pointing to. This is better clarified by the following figure (don't worry about Python 3.3, this is a feature that hasn't changed):

The right part of the preceding figure depicts the state of the program when execution has reached the end, after func has returned (None). Take a look at ...

Get Learn Web Development with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.