forked from zahariev-webbersof/python-mini-projects
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass_example.py
More file actions
Latest commit
21 lines (16 loc) · 469 Bytes
/
Copy pathclass_example.py
File metadata and controls
21 lines (16 loc) · 469 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
classCar:
def__init__(self, make, model, year, speed):
self.make=make
self.model=model
self.year=year
self.speed=speed
defhonk(self):
print("Beep beep!")
defaccelerate(self, rate):
self.speed+=rate
defget_speed(self):
returnself.speed
my_car=Car("Toyota", "Camry", 2020, 0)
my_car.honk() # Output: "Beep beep!"
my_car.accelerate(30)
print(my_car.get_speed()) # Output: 30