Created
November 13, 2020 12:52
-
-
Save betterdatascience/6618859be9e01673a559992abe08a0a3 to your computer and use it in GitHub Desktop.
003_oop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Car: | |
def __init__(self, brand, color, plate): | |
self.brand = brand | |
self.color = color | |
self.plate = plate | |
def start(self): | |
return f'{self.color} {self.brand} started!' | |
@staticmethod | |
def stop(): | |
return 'All systems stop!' | |
def _check(self): | |
return 'Private method' | |
def __str__(self): | |
return f'Brand: {self.brand}, Color: {self.color}, Plate: {self.plate}' | |
__repr__ = __str__ | |
cars = [Car(brand='Audi', color='Black', plate='XYXY-123'), | |
Car(brand='BMW', color='Purple', plate='QWER-321')] | |
print(cars[0]) | |
print(cars[0].start()) | |
print(cars[0].stop()) | |
print(cars[0]._check()) | |
print(cars) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment