Classes & Objects in Python
Chapter 21: Classes & Objects
4 short lessons, with 3D animations, quizzes and coding tasks.
The lessons
Classes and objects
A class is a blueprint, and each object made from it carries its own values in attributes.
Methods
A method is a function written inside a class, and obj.method() runs it with self set to that object.
Methods that change an object
A method can change its own object's attributes through self, so each object keeps its own state, and the methods are the safe way to change it.
Class attributes and instance attributes
An attribute set with self. belongs to one object, an attribute written in the class body belongs to the class and is shared by all its objects, and Python looks in the object first, then the class.