Skip to contentSkip to navigation

Object-Oriented Programming

Object-Oriented Programming — cheat sheet

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

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.

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