What do three cats and three wild rabbits have in common that tells you exactly which data attributes an Animal class needs?
Short drills on what this video just taught. Write the code, run the checks, and reveal the answer only if you are stuck.
You are designing a Cat data type, and five things it might bundle up are listed below. Sort each one into the two kinds of attribute a class holds.
Assign to kinds a list of five strings, one per item and in that order. Each string is either "data" or "procedure".
Classes as real-world categorization
Write down the cats-and-rabbits example: three cats share name, age and color plus one set of behaviors, wild rabbits share a different set with no name, and a class records that description once.
Data attributes versus procedural attributes
Record that data attributes are the variables the designer picks, x and y for a coordinate and age for an animal, while procedural attributes are the methods a user of the object calls.
class Animal(object) and the __init__ method
Write out the four-line class definition, name object as Animal's parent, and state that every method's first parameter is self, a stand-in for an object that does not exist yet.
self.age against a plain local variable
Note that self.age = age creates a data attribute lasting as long as the object while a bare age vanishes when __init__ ends, then trace a = Animal(4), where the new object is self.