Lecture 18 - More Python Class Methods Flashcards
(1 cards)
1
Q
Are the 3 expressions below equivalent?
4 * 3 (4).\_\_mul\_\_(3) int.\_\_mul\_\_(4,3)
A
Yes, all of them will multiply int
4 by int
3, returning int
12.
The *
operator is just a shorthand for the \_\_mul\_\_
special method (multiplication), making Python code easier to write.
Regarding the method call for the first two cases, the int
4 will be passed to self
, and the int
3 will be passed as the other argument.
The first two expressions are calls to an instance, whitle the last one is a call to the class itself.