Five Dunder Methods in Python You Should Know About

Five Dunder Methods in Python You Should Know About

Also called Magic Methods, Dunder Methods are necessary to understand Python

In my last post, I talked about Object-Oriented Programming(OOP). And I specifically talked about a single magic method __init__ which is also called as a constructor method in the OOP terminology.

The magic part of __init__ is that it gets called whenever an object is created automatically. But it is not the only one in any sense. Python provides us with many other magic methods that we end up using without even knowing about them. Ever used len()print() or the [] operator on a list? You have been using dunder methods.

In this post, I would talk about five of the most used magic functions or “dunder” methods.

1. Operator Magic methods: __add__ , __sub__ , __mul__ , __truediv__ , __lt__ , __gt__

Everything in Python is an object, ranging from the data types int,str ,float to the models, we use in data science. We can call methods on an object, like this str object

Fname = "Rahul"

## Now, we can use various methods defined in the string class using the below syntax
Fname.lower()

data-science python artificial-intelligence machine-learning programming

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Data Science Projects | Data Science | Machine Learning | Python

Practice your skills in Data Science with Python, by learning and then trying all these hands-on, interactive projects, that I have posted for you.

Data Science Projects | Data Science | Machine Learning | Python

Practice your skills in Data Science with Python, by learning and then trying all these hands-on, interactive projects, that I have posted for you.

Data Science Projects | Data Science | Machine Learning | Python

Practice your skills in Data Science with Python, by learning and then trying all these hands-on, interactive projects, that I have posted for you.

Data Science Projects | Data Science | Machine Learning | Python

Practice your skills in Data Science with Python, by learning and then trying all these hands-on, interactive projects, that I have posted for you.

Data Science Projects | Data Science | Machine Learning | Python

Practice your skills in Data Science with Python, by learning and then trying all these hands-on, interactive projects, that I have posted for you.