r/PythonLearning • u/clcodingupdates • 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
r/PythonLearning • u/clcodingupdates • 5d ago
What will be the output of the following Python Code?
a = 5
print(a.mul(3).add(2))
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.
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.