Skip to content

Instantly share code, notes, and snippets.

View J-Yaghoubi's full-sized avatar
💯
Always ready

Seyed Jafar Yaghoubi J-Yaghoubi

💯
Always ready
View GitHub Profile
@spinfish
spinfish / subclass_example_and_more.py
Last active December 29, 2024 14:07
Here we have an example of how subclasses work in Python (how to override methods of a parent class), how to set attributes for the subclass, how class methods/static methods work and how they can be useful, and a basic coverage of what the property decorator can do.
class Car:
"""A class written to showcase what instance/static/class methods/properties are."""
# All of the methods defined below (including __init__) will be inherited by subclasses.
# Here in the __init__ constructor there is a positional parameter, `name`,
# followed by two keyword-only arguments (or "kwargs"), `doors` and `max_speed`,
# which have default values of 4 and 150, respectively.
# In Python, any parameters following a * in a function definition will be kwargs.
def __init__(self, name: str = None, *, doors: int = 4, max_speed: int = 150):