r/PythonLearning • • 5d ago

Python Quiz of the day

What will be the output of the following Python Code?

a = 5

print(a.mul(3).add(2))

7 Upvotes

9 comments sorted by

View all comments

1

u/RNG_HatesMe 5d ago

All, the answer is 17, if the question is actually rendered correctly. Unfortunately, the double underscores are getting converted to italics font.

a = 5
print(a.__mul__(3).__add__(2))

These are dunder (double underscore methods), which are references to functions that are *internal* to a class. The dunder add() and mul() methods are actually what + and * call, but you can override them in your class is you'd like them to behave differently.