Combining Data and Behavior
What are some common properties of cars?
What are some actions you can perform?
>>> s = 'Hello World' >>> type(s) <class 'str'> >>> l = list() >>> type(l) <class 'list'> >>> dir(l) ['__add__', '__class__', ...]
class Pet(): def __init__(self, name): self.name = name
class Pet(): def __init__(self, name): self.name = name def eat(self): print('Nom nom nom')
class Pet(): def __init__(self, name): self.name = name def eat(self, food): print(f'Nom nom. {self.name} likes {food}.') >>> mypet = Pet('Spot') >>> mypet.eat('dogfood') Nom nom. Spot likes dogfood.