class, __init__ and self
A class is a blueprint. class Beat: describes what every beat has; Beat() builds one (an object). __init__ runs when it's built, and self.kicks = … gives that object its own attribute.
Lesson 2: a Track object that plays itself, twice.
class Track:
def __init__(self, drum, beats):
self.drum = drum
self.beats = beats
def play_at(self, offset):
for b in self.beats:
self.drum(b + offset)
def twice(self):
self.play_at(0)
self.play_at(4)
Track(kick, [1, 3]).twice()Challenge A:Inside __init__, set self.kicks = [1, 5]. Then build one: b = Beat(), and play kick(b.kicks).