Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Init uses same name as attribute and getters

  • init
  • self
class Point:
    def __init__(self, x, y):
        self.x = x
        self.y = y

from shapes2 import Point

p1 = Point(2, 3)
print(p1)          # <shapes2.Point object at 0x7f2c22c1ec70>
print(p1.x)        # 2
print(p1.y)        # 3

p2 = Point(y=7, x=8)
print(p2)          # <shapes2.Point object at 0x7f2c22c1e700>
print(p2.x)        # 8