On Sun, 27 Sep 2020 15:18:44 +0800 Stephane Tougard <steph...@sdf.org> wrote:
> On 2020-09-27, 2qdxy4rzwzuui...@potatochowder.com > <2qdxy4rzwzuui...@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. > > It is very good that you try out things. Nevertheless, it is also good to read. In other words the combination of reading and trying out things is the best way to make progress. Here some pointers pass - http://localhost:2015/tutorial/controlflow.html#pass-statements about variables - https://realpython.com/python-variables/ Regarding your question above: As long as `name` is not attached to an object it doesn't exist and the error message above is correct. You have to assign a value (or object as everything is an object in Python) to `name`, Then you can use it. (In comparison to guys like ChrisA and StefanR and others here I am also a Python beginner) -- Manfred -- https://mail.python.org/mailman/listinfo/python-list