Why does `self.x = x` guarantee every Coordinate carries an x, when the plain parameter `x` vanishes the moment `__init__` returns?
Short drills on what this video just taught. Write the code, run the checks, and reveal the answer only if you are stuck.
Song is a brand new data type, but its body is empty so far. Put the implementer's hat on first: give Song an __init__ taking a title and a length in seconds, and store both of them as data attributes named title and seconds, so that every Song ever built is guaranteed to carry them.
Then swap hats and use the finished type: build the song "Blackbird", 138 seconds long, and assign that object itself to song.
The implementer's view and the user's view
Set the two perspectives side by side against defining versus calling a function, recording what the implementer settles in the abstract and what the user creates and manipulates.
The two flavors of attributes
Write down that a class is made of data attributes, the variables that make up the object, and behaviors, the methods, and label each part of Coordinate as one or the other.
__init__ as the constructor and the role of self
Write the class Coordinate(object) header and its __init__, note that creating an object supplies values for everything other than self, and mark self.x and self.y as data attributes.
The xval and yval variant of the constructor
Rewrite the constructor with parameters xval and yval and the assignments self.x = xval and self.y = yval, and record which names are the data attributes here.