4 ms·
Also see assignment expressions recently adopted in python 3.8: https://www.python.org/dev/peps/pep-0572/ https://www.python.org/dev/peps/pep-0572/
by cocoflunchy 7y ago
Also see assignment expressions recently adopted in python 3.8: https://www.python.org/dev/peps/pep-0572/ https://www.python.org/dev/peps/pep-0572/
- sbergot 7y agoIn Python things are a bit different because declarations and assignments are ambiguous.
- empyrical 7y agoAlso its addition to Python was controversial, to say the least. (I have been enjoying using it, however)
- masklinn 7y agoThey're not ambiguous, assignments are declarations unless the variable was pre-declared (via global or nonlocal). Assignment was specifically made a statement to avoid the confusion / typo risks of `=` v `==`.
- sbergot 7y agoThey are not ambiguous if you have the whole file in your head. This is why there are keywords like "global" & "nonlocal".
- masklinn 7y ago> They are not ambiguous if you have the whole file in your head. They're not ambiguous period, python's `=` always performs a local declaration unless overridden via the keywords you mentioned. > This is why there are keywords like "global" & "nonlocal". It's the exact opposite of your statement: `global` and `nonlocal` indicate non-local bindings, because by default all bindings are local and you do not need to have "the whole file in your head".