Object oriented programming
Source: Corey Schafer, Youtube, GitHub code
- Everything is an ‘Object’ in python
- We can create own objects, ‘classes’
- In class:
- function -> method
- variable -> attribute
- Class <-> instance of a class is not the same.
- The class itself is a blueprint, a template for generating instances.
- class variable vs. instance variable
- ‘self’ argument:
- The instance itself
- passed automatically
__init__(self)super()Detailed video on super
Part 2
Text representation
When we call the print statement, Python first looks for the __str__ method defined in your class before falling back on the __repr__ method.
__repr____str__
Math
__add____sub____mul____truediv__- …
Context manager
Alternative constructor
Getter_setter
@property decorator