---
title: "Discussion on \"TIL: \"Double Underscores\" have a name - Dunder 😂\" | Hashnode"
description: "Discussion on \"TIL: \"Double Underscores\" have a name - Dunder 😂\". How many times have you encountered names like __init__, __test__, __doTask___ and so on? These are called Dunders or Double Underscores and are commonly used for operator overloading. \nMore details here: https://www.geeksforgeeks.org/dunder-magic-me..."
url: "https://hashnode.com/posts/til-double-underscores-have-a-name-dunder/5d9487be9d9cb4c65809ad60"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [TIL: "Double Underscores" have a name - Dunder 😂](https://sandeep.dev/blog/til-double-underscores-have-a-name-dunder?utm_source=hashnode&utm_medium=feed)

How many times have you encountered names like \_\_init\_\_, \_\_test\_\_, \_\_doTask\_\_\_ and so on? These are called Dunders or Double Underscores and are commonly used for operator overloading. More details here: https://www.geeksforgeeks.org/dunder-magic-me...

Oct 2, 2019 · sandeep.dev  
Read the article

-   [#til](https://hashnode.com/tag/til)

## Written by

[Sandeep Panda](https://hashnode.com/@sandeep)

@sandeep · Bangalore

  
[View profile](https://hashnode.com/@sandeep)

co-founder, Hashnode

I am the Co-Founder of Hashnode. I write (about) code and keep interest in Venture Funding and startups. Feel free to contact me at sandeep@hashnode.com.

## Responses 5

Markdown supported · ⌘↵ to post

[trav](https://hashnode.com/@techsavvytravvy)

[Jul 26, 2022](https://hashnode.com/posts/til-double-underscores-have-a-name-dunder/5d9487be9d9cb4c65809ad60/comment/62e07dd238585e9ea517703f)

Wait, is Dunder what the type of method is called? I thought it just meant "double underscore". Like "dunder init dunder." I can't say "dunder" with a straight face lol.

Also would it be camelCase between the dunders, or snake\_case? Asking the important questions here.

[Shad Mirza](https://hashnode.com/@iamshadmirza)

[Aug 19, 2020](https://hashnode.com/posts/til-double-underscores-have-a-name-dunder/5d9487be9d9cb4c65809ad60/comment/5f3ce18c2324e0296c44f8d8)

TIL: Dunders

[Gautam Kumar](https://hashnode.com/@gautamkumar26265)

[May 3, 2022](https://hashnode.com/posts/til-double-underscores-have-a-name-dunder/5d9487be9d9cb4c65809ad60/comment/5f3ce18c2324e0296c44f8d8#reply-6270c7ec339f0101810208d8)

This post is really amazing [walmartone.tech](https://walmartone.tech/)

[kelwein](https://hashnode.com/@melwein)

[Dec 11, 2019](https://hashnode.com/posts/til-double-underscores-have-a-name-dunder/5d9487be9d9cb4c65809ad60/comment/5df108d3acdafdac270d658c)

Its nice to know these many features. Love this. Thanks [Walmartone](https://walmartone.me/)

[Francisco Quintero](https://hashnode.com/@cesc1989)

[Nov 18, 2019](https://hashnode.com/posts/til-double-underscores-have-a-name-dunder/5d9487be9d9cb4c65809ad60/comment/5dd2ea56ecde1000787459ac)

Well, TIL for me as well. I never really imagined they'd had a name 😁

Cool to know.

[Sébastien Portebois](https://hashnode.com/@sportebois)

[Oct 7, 2019](https://hashnode.com/posts/til-double-underscores-have-a-name-dunder/5d9487be9d9cb4c65809ad60/comment/5d9bb47cb0c87f416092d593)

Dunders, or magic methods, or double-underscore methods, are definitely one of the great things in Python: once you start understanding how Python works, you can really leverage these and make your code much more pythonic.

Adding some dunders to your custom classes transform them to iterables, or other useful types. e.g. If you add `__len__` and `__getitem__` to your class and you can make use it like an interable. Add an `__enter__` and an `__exit__` and you can use your custom context in a `with ...as ...:` block (and get all the benefits, like the guarantee the `__exit__` will be called even if an exception is raised.

The «Fluent Python» book really introduced me to these a while ago, and it was the big change. For instance, once you get this, you understand why Python has a `len(obj)` built in function rather than a `obj.len()` method: any object which implements a `__len__(self):` method can be called with `len(obj)`, and this `__len__` is also used for other constructs (like the iterable). When I started learning Python, I was always bugged by this `len()` requiring the object has an argument. Once I understood the dunder paradigm and how it helps the developer implement behaviors using composition, it all made sense and became much more easier to remember (and leverage!)

Recommended reading: Fluent Python (from O’Reilly)

And Raymond Hettinger’s «Beyond PEP8» talk with live code refactoring is a great example on how to leverage dunders to make the code more pythonic, and hide the boilerplate to make the code shorter and focused on the business logic. Really a recommended talk! : [youtube.com/watch](https://www.youtube.com/watch?v=wf-BqAjZb8M)
