rezamalik15

contoh class di python

Aug 10th, 2023
879
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.61 KB | None | 0 0
  1. class Vehicle:
  2.     brand = ""
  3.     model = ""
  4.     color = ""
  5.     maxSpeed = ""
  6.  
  7.     def __init__(self, brand, model, color, maxSpeed):
  8.         self.brand = brand
  9.         self.model = model
  10.         self.color = color
  11.         self.maxSpeed = maxSpeed
  12.  
  13.     def start(self):
  14.         print(f"{self.brand} {self.model} is starting the engine")
  15.    
  16.     def stop(self):
  17.         print(f"{self.brand} {self.model} is stopping the engine")
  18.    
  19.     def turn(self, direction):
  20.         print(f"{self.brand} {self.model} is turning {direction}")
  21.    
  22. vehicle1 = Vehicle("Toyota", "Sedan", "Black", 300)
  23. vehicle1.start()
Advertisement
Add Comment
Please, Sign In to add comment