Anonymous user
Variable declaration reset: Difference between revisions
m
→{{header|Python}}: more explanation
Catskill549 (talk | contribs) (added AWK) |
m (→{{header|Python}}: more explanation) |
||
Line 432:
=={{header|Python}}==
In Python, variables are not declared before use. If you assign to a non-existent variable, you create a new variable with that name. The language does not prohibit writing code to read a variable that may or may not exist. But if the code tries at runtime to read a variable that happens to not have been assigned to (or a variable that happens to have been `del`'ed), you get a `NameError` exception at runtime.
In Python, variables are supposed to be defined before they are used. The code does run, but note that a Python code checker such as pyflakes will flag such code with an error. ▼
▲
<lang python>
s = [1, 2, 2, 3, 4, 4, 5]
|