Python OOP: Classes & Objects

What is a Class?

A class is a blueprint used to create objects.

Loading...
Output:

Creating Objects

An object is an instance of a class.

Loading...
Output:

Constructor (__init__)

The constructor initializes object data.

Loading...
Output:

Attributes

Attributes store data inside objects.

Loading...
Output:

Methods

Methods are functions inside a class.

Loading...
Output:

The self Keyword

self refers to the current object.

Loading...
Output:

Modify and Delete Properties

Loading...
Output:

Practice

Create a Student class with a method to calculate average grades.

Loading...
Output:

Need Help?