Learn Python - Classes

What are classes in Python? Classes are a user-defined blueprint from which objects can be created.

CuriosityDeck
Python in Plain English
2 min readJan 9, 2022

Python is an Object Oriented Programming Language. Almost everything in Python is an object including its properties and methods. Classes are a user-defined blueprint from which objects can be created. Creating a new class creates a new type of object, allowing new instances of that type to be made. Each class instance can have attributes attached to it for maintaining its state.

Object

An object is an instance of a class. You can create different instances/objects for a class with different properties.

Output:

__init__() Method

__init__() is similar to a constructor and is used to initialize the class's state. It runs as soon as an object of a class is instantiated. The method is useful to do any initialization you want to do with your object.

Output:

Methods in a Classes

You can also define methods inside a class. A different instance can access the methods with different input parameters.

Output:

Self Parameter

The self parameter is similar to a pointer in C++, it refers to a particular instance of the class. It is passed along with methods (first parameter) and is used to access variables that belong to the class.

Output:

Modify the Object Properties

The change in one instance of the object will not affect other instances.

Output:

The classes form the backbone of oops programming languages. Here we have discussed the basics of class in Python. Hope you have understood.

For more, you can refer to the following:

For practice and examples, go here:

More content at plainenglish.io. Sign up for our free weekly newsletter. Get exclusive access to writing opportunities and advice in our community Discord.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

What are your thoughts?