Object-oriented programming (OOP) in Python

Daniel V.
2 min readSep 29, 2020

Classes are a fundamental tool in any respectable programming language.

What’s a class?

Think of a class as a template for creating objects with related data and functions that do interesting things with that data.

Python makes it easy to create and use classes. In fact, most other programming languages are quite jealous of Python for its elegance and simplicity.

Today, we will discuss this amazing topic!

What’s a class attribute?

Because a class stores data and perform tasks, this data is called “attributes” which can be defined as the characteristics of a class. This is shared between all other objects of the same class.

What’s s instance attribute?

Is a characteristic belonging to only one object. It’s only accessible in the scope of the object owner of that characteristic

Ways to create objects in Python

Non-Pythonic way:

In this way, we can’t change the values after

So… a solution for this is use getter and setter property methods in a Pythonic way:

Differences between class and instance attributes and advantages of twice

The difference is that when we change the value of a class attribute, this change affects all the instances (objects) of that class.

A change in an attribute of the instance (object) only affects that object and no instance of that same class

Built-in class attribute __dict__

This is the dictionary containing the module’s symbol table. A dictionary or other mapping object used to store an object’s attributes.

Python deals with this class attribute storing each instance in a dictionary.

So… That’s it’s all, thank’s for reading this blog.

--

--