Namespaces - Names are labels for identification. We use a name to refer to a thing. Several objects can have the same name, and this can create problems, calling out 'Robert' in a crowd, for instance. A thing can have many names, and this is ok, you call your friend Robert, Bob.
MicroPython has two groups of names:
We also have symbols +, *, - and alike.
Implicit names are keywords and builtins. Keywords defined the language and can not be
reuse.
Statement in = 23 will give you SyntaxError, while id = 23 is ok. The difference is that the word in is a keyword and
id is a builtin.
Names created in our codes, functions, class, variables, are examples of explicit names. You can delete an explicit name using del. You will get NameError if you try to delete an implicit name.
There are two types of object:
Each name has three scopes:
Scopes and namespaces are related, nested, sort of matryoshka dolls.
We can use a class to create a namespace in MicroPython. We can accomplish this by:
class NS:
pass
x = NS()
x.a = 1
x.b = 'one'
MicroPython is Python, quiet but not quiet.
MicroPython has two groups of names:
- implicit
- explicit
We also have symbols +, *, - and alike.
Implicit names are keywords and builtins. Keywords defined the language and can not be
reuse.
Statement in = 23 will give you SyntaxError, while id = 23 is ok. The difference is that the word in is a keyword and
id is a builtin.
Names created in our codes, functions, class, variables, are examples of explicit names. You can delete an explicit name using del. You will get NameError if you try to delete an implicit name.
There are two types of object:
- basic
- composite
Each name has three scopes:
- global
- nonlocal
- local
Scopes and namespaces are related, nested, sort of matryoshka dolls.
We can use a class to create a namespace in MicroPython. We can accomplish this by:
class NS:
pass
x = NS()
x.a = 1
x.b = 'one'
MicroPython is Python, quiet but not quiet.
Comments
Post a Comment