Python Tip #240 (of 365): Dunder methods are meant to be defined, but not called...

@treyhunner@mastodon.social

Python Tip #240 (of 365):

Dunder methods are meant to be defined, but not called.

Do this:
str(today)

Not this:
today.__str__()

Why avoid calling dunder methods?

Mostly because you're not supposed to.

Dunder methods are a contract between Python and whoever wrote the class: Python calls them, we use the operations they power.

๐Ÿงต (1/3)

#Python #DailyPythonTip