self
self
is a reference to the current instance of the class.
It is used to access variables that belongs to the class.
class Person: def __init__(self, name, age): self.name = name self.age = age
It does not have to be named self
, you can call it anything, but it has to be the first parameter of any function in the class.
class Player: def __init__(hello, name): hello.name = name def print_player_name(hello): print(hello.name) player = Player("John") player.print_player_name() # John