__add__()
Let's add two variables, x
and y
:
When Python executed this code, it called the __add__
method on x
, passing it y
:
The add
method is called when using the +
operator. We can define a custom add
method for our class.
p1 + p2
is equal to p1._add__(p2)
OutPut
Last updated