Skip to contentSkip to navigation

Classes and Objects

Classes and Objects, cheat sheet

Design modular, reusable systems with classes, inheritance, and properties.

01

Classes and constructors

class User:
    def __init__(self, name):
        self.name = name
Constructor initializing instance state.
@classmethod
def factory(cls): return cls()
Alternative constructor receiving cls.

02

Properties and magic methods

@property
def price(self): return self._price
Getter attribute wrapper.
def __str__(self): return self.name
User-friendly string representation.
All cheat sheets