[docs] What are the rules for local and global variables in Python?
julien at palard.fr
Sun Jul 7 17:21:58 EDT 2019
Hi Will, thanks for reporting!
> The text reads that variables which are _only_ referenced *inside* a function will be global, surely this should be *outside*, which I think would also make the following sentence make more sense.
Stransgely enough, the documentation is right: there's a distinction between "referenced" and "assigned":
- If a name is only referenced in a function, it's a global.
- If a name is assigned in a function, it's a local (unless declared explicitly as global).
VAL = 42
In this case, VAL is only referenced inside function foo, so it's global.
More information about the docs