tutorialsPythonBasic.verybasic.functions.function_local_variables module

Remember that the variables passed to a function are local, even if they are named the same as one of the “outside” variables.


Add one to the number and print it, showcasing local variables.

Let’s create a variable named x and set it to a number

>>> x = 5

Let’s call the function

>>> add_one_and_print(x)

Obviously the ‘x’ inside the function changed to 6, what about the “outside” one?

>>> x

It’s still 5, since the ‘x’ inside the function was a local variable.