Classes and instances

A class is a template that groups data (attributes) and behaviors (methods). An instance is an object created from the class. The __init__ method initializes the attributes and self refers to the current instance.

Example

class Chien:
    def __init__(self, nom):
        self.nom = nom
rex = Chien('Rex')

Related concepts

The whole glossary