Initialize an instance - (not a constructor), attributes and getters


In Python we dont explicitely declare attributes so what people usually do is add a method calles __init__ and let that method set up the initial values of the insance-object.

examples/oop/attributes/shapes.py
class Point:
    def __init__(self, a, b):
        self.x = a
        self.y = b

examples/oop/attributes/use_shapes.py
from shapes import Point

p1 = Point(2, 3)
print(p1)          # <shapes.Point instance at 0x7fb58c31ccb0>
print(p1.x)        # 2
print(p1.y)        # 3

p2 = Point(b = 7, a = 8)
print(p2.x)