December 2018
Beginner to intermediate
796 pages
19h 54m
English
After the class object has been created (which usually happens when the module is first imported), it basically represents a namespace. We can call that class to create its instances. Each instance inherits the class attributes and methods and is given its own namespace. We already know that, to walk a namespace, all we need to do is to use the dot (.) operator.
Let's look at another example:
# oop/class.namespaces.pyclass Person: species = 'Human'print(Person.species) # HumanPerson.alive = True # Added dynamically!print(Person.alive) # Trueman = Person()print(man.species) # Human (inherited)print(man.alive) # True (inherited)Person.alive = Falseprint(man.alive) # False (inherited)man.name = 'Darth'man.surname ...Read now
Unlock full access