Puzzle 1: Explanation
Let’s find out how attribute lookup works in Python.
We'll cover the following...
We'll cover the following...
Let’s try it!
Try executing the code below to verify the results:
Code explanation
When we write self.count, we’re doing an attribute lookup. The attribute that we’re looking for in this case is count. Getting an attribute in Python is a complex operation. Almost every Python object stores its attributes in a dict called __dict__.
Python will first try to find the attribute in the instance dictionary, then in ...