In Python, the constructor is a special method called __init__. It runs automatically when you create an object from a
class.
This page covers Constructor in Python. For a language-agnostic introduction, see Constructor.
Defining __init__#
Like all instance methods in Python, __init__ takes self as its first parameter. Additional parameters receive the values passed when creating the object.
class Player:
def __init__(self, name):
self.name = nameself.name = name stores the argument on the object.