Python Namespace Explained in Code - Python Tutorial #10

Published: 17 March 2018
on channel: DMK Data
408
16

After talking about the theory of namespaces and assignments in the last video I now want to look at namespaces in the actual code. With the dir() function we can take a look at all the names that currently exist in the namespace dir() is called in and when we assign a new name it will show up when calling dir(). The id() function on the other hand allows us to take a peek into the object space. id(name) gives us the address in memory of the object name is referencing.

The id() function is mostly for educational purposes since we don't have to care where exactly an object is living in memory but for mutable objects we care if two names refer to the same object. For that we use the 'is' keyword. This keyword is a boolean operator that returns True if both names refer to the same object. That is different from the equality operator which compares names by value rather than object location. Because the 'is' keyword compares object location : name1 is name2 is synonymous with
: id(name1) == id(name2) but it NOT synonymous with :name1 == name2

Python:
https://www.python.org/

Outro Song:
Alright by Silent Partner is part of the YouTube Audio Library.


On this page of the site you can watch the video online Python Namespace Explained in Code - Python Tutorial #10 with a duration of hours minute second in good quality, which was uploaded by the user DMK Data 17 March 2018, share the link with friends and acquaintances, this video has already been watched 408 times on youtube and it was liked by 16 viewers. Enjoy your viewing!