Back to search

Classes, objects, `self`, `__init__`, and class vs instance variables

A class defines shared behavior, each object holds instance state, `self` refers to the current instance, and `__init__` initializes it.

Python Easy Theory

Classes, objects, `self`, `__init__`, and class vs instance variables

A class defines shared behavior, each object holds instance state, `self` refers to the current instance, and `__init__` initializes it.

  • Instance variables belong to each object
  • Class variables are shared on the class
  • `self` is just a normal first parameter by convention

Classes, objects, `self`, `__init__`, and class vs instance variables