Files
Learn-Python-Programming-Th…/ch01/bike.py
T
adii1823 ff85709895 ch01
2021-10-28 16:58:30 +05:30

23 lines
626 B
Python

# let's define the class Bike
class Bike:
def __init__(self, colour, frame_material):
self.colour = colour
self.frame_material = frame_material
def brake(self):
print("Braking!")
# let's create a couple of instances
red_bike = Bike('Red', 'Carbon fiber')
blue_bike = Bike('Blue', 'Steel')
# let's inspect the objects we have, instances of the Bike class.
print(red_bike.colour) # prints: Red
print(red_bike.frame_material) # prints: Carbon fiber
print(blue_bike.colour) # prints: Blue
print(blue_bike.frame_material) # prints: Steel
# let's brake!
red_bike.brake() # prints: Braking!