Shadowing and Parameters
A function can read a global variable. But when it assigns to a name that also exists globally, it creates a new local variable that shadows the global one. The global is untouched.
Parameters are local too. When you pass a value into a function, the parameter is a fresh local name holding a copy of that value. Reassigning the parameter inside the function does not touch the caller's variable.
✦ The exception worth knowing
Lists and dictionaries behave differently. Passing one in does not copy it, it passes a reference to the same object, so changing its contents inside a function DOES affect the caller. Numbers and strings are copied, collections are shared. Module 18 works through this properly.
Mark this lesson complete
Signed in, your progress follows you to every device.