> Borrowing from Perl, the keyword 'my' is used to declare an explicitly > scoped variable: > > def f1(): > my x = 1 > def f2(): > x = 2 # Does not create a new x > > In the above example, the statement 'my x = 1' declares that the scope > of the variable 'x' is the outer function f1. Any assignment to x will > modify the existing x, rather than creating a new definition. -1, for this reason: def f() x = 2 # Does this create a local variable? Today, the answer is yes. Under this proposal, you can't answer the question without inspecting the entire context in which f is defined. For that reason, I would much rather have the first assignment in a block say explicitly whether it is intended to create a local variable: def f1(): x = 1 def f2(): global x x = 2 # Does not create a new x This might even be abbreviated: def f1(): x = 1 def f2(): global x = 2 # Equivalent to the last example above
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4