What is namespace | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What is namespace

28th Jan 2021, 8:30 PM
Angello
Angello - avatar
4 Answers
+ 8
You can think of a namespace as a dictionary in which the keys are the object names and the values are the objects themselves.
28th Jan 2021, 8:32 PM
Adamyan
Adamyan - avatar
+ 7
A way to separate variables to avoid name clashes.
28th Jan 2021, 10:04 PM
Sonic
Sonic - avatar
+ 6
For example in Python, how you reach your variables varies with where they are. Consult the LEGB-modell: L: Local variables are inside a function. You can’t reach them from outside the function. E: Enclosing variables are variables you are trying to reach in an function from an nested function to that function you are trying to reach. To read it is always okey, but if you want to change it, you have to first declare it with nonlocal. G: Global variables are variables in the modul layer. You can read them from inside a function, but if you want to change them, you have to first declare them as global. B: Bult-in variables are variables in the built-in layer. If you for example assign len = 2 in the modul layer, you have to delete it first if you want to use the function len([1, 2, 3]), because your assignment otherwise will block the function in the built-in layer. So from L you reach variables in LEGB, from E in EGB, and from G in GB. Hope this gives you a hint about namespsces. /Regards Per B
28th Jan 2021, 10:13 PM
Per Bratthammar
Per Bratthammar - avatar
+ 4
Thanks!
28th Jan 2021, 9:35 PM
Angello
Angello - avatar