Skip to content

Instantly share code, notes, and snippets.

@wpeterw
Created October 22, 2022 18:26
Show Gist options
  • Save wpeterw/69db723490ee701cdf766948aa42a44a to your computer and use it in GitHub Desktop.
Save wpeterw/69db723490ee701cdf766948aa42a44a to your computer and use it in GitHub Desktop.
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