Created
October 22, 2022 18:26
-
-
Save wpeterw/69db723490ee701cdf766948aa42a44a to your computer and use it in GitHub Desktop.
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 Cars: | |
# Class attribute | |
fuel = "Petrol" | |
# Instance attributes | |
def __init__(self, brand: str, model: str, year: int, color: str): | |
self.brand = brand | |
self.model = model | |
self.year = year | |
self.color = color | |
# class method | |
@classmethod | |
def car_fuel(cls, fuel: str): | |
cls.fuel = fuel | |
# instance method | |
def car_details(self): | |
return f"Brand: {self.brand} Model:{self.model} Year: {self.year} Fuel: {self.fuel}, Color: {self.color}" | |
# static method | |
@staticmethod | |
def car_color(color: str): | |
if color == "white": | |
return "white" | |
if color != "white": | |
return "not white" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment