This is a draft cheat sheet. It is a work in progress and is not finished yet.
Class - Syntax
class Dog(object):
living = True
age = 0
def __init__(self, name, sex):
self.name = name
self.sex = sex
def bark(self):
print(f"{self.name} barked!")
luke = Dog('Luke', 'Male')
print(f"Name: {luke.name}")
print(f"Sex: {luke.sex}")
print(f"Living: {luke.living}")
print(f"Age: {luke.age}")
luke.bark()
|
Name: Luke
Sex: Male
Living: True
Age: 0
Luke barked!
Class - Magic Methods
|
Overrides object creation method |
|
Overrides object string representation |
|
Overrides + operator |
|
Overrides - operator |
|
Overrides * operator |
__floordiv__(self, other)
|
Overrides // operator |
__truediv__(self, other)
|
Overrides / operator |
|
Overrides % operator |
__pow__(self, other[, modulo])
|
Overrides ** operator |
|
Overrides < comparison operator |
|
Overrides <= comparison operator |
|
Overrides == comparison operator |
|
Overrides != comparison operator |
|
Overrides >= comparison operator |
|
Overrides > comparison operator |
__call__(self[, args...])
|
Overrides ( ) operator |
|
Overrides int() method |
|
Overrides float() method |
|
Overrides str() method |
|
Overrides abs() method |
|
Overrides len() method |
__contains__(self, item)
|
Overrides in keyword behavior |
OOP - Inheritance
class Vehicle(object):
def honk(self):
print('Honk honk')
class Car(Vehicle):
def accelerate(self):
print('Vrooom')
honda = Car()
honda.honk()
honda.accelerate()
|
|
|
|