Use of a variable in parent loop
Chris Angelico
rosuav at gmail.com
Sun Sep 27 07:16:54 EDT 2020
On Sun, Sep 27, 2020 at 9:01 PM Stephane Tougard via Python-list
<python-list at python.org> wrote:
>
> On 2020-09-27, 2QdxY4RzWzUUiLuE at potatochowder.com <2QdxY4RzWzUUiLuE at potatochowder.com> wrote:
> > As ChrisA noted, Python almost always Just Works without declarations.
> > If you find yourself with a lot of global and/or nonlocal statements,
> > perhaps you're [still] thinking in another language.
>
>
> I don't really agree with that, trying to use an undeclared
> object/variable/whatever :
>
> Python 3.7.7 (default, Aug 22 2020, 17:07:43)
> [GCC 7.4.0] on netbsd9
> Type "help", "copyright", "credits" or "license" for more information.
> >>> print(name)
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> NameError: name 'name' is not defined
> >>>
>
> You can say it's not the "declaration" the issue, it's the "definition",
> that's just a matter of vocabulary and it does not answer the question.
>
> In many non declarative language, if I do print($var), it just prints
> and undefined value with returning an error.
>
>>> name = "Fred"
>>> print(name)
Fred
Lack of declaration doesn't imply that every variable is initialized
to some null value.
ChrisA
More information about the Python-list
mailing list