Dunder Method

say it: “DUN-der METH-ud” /ˈdʌndər ˈmɛθəd/

A method with double underscores, like __len__, that Python calls for you.

What is a dunder method?

A dunder method has double underscores on both sides, like __init__ or __len__. Python calls these for you at the right moment, such as when you use len() on your object.

class Playlist:
    def __init__(self, songs):
        self.songs = songs

    def __len__(self):
        return len(self.songs)

print(len(Playlist(["A", "B", "C"])))  # 3

Level: Journeyman · More Python terms at this level

Updated