ch01
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
# 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!
|
||||
Reference in New Issue
Block a user