Gooner
Gooner

Reputation: 1398

How does Python evaluate this expression?

How does Python evaluate the following expression? anim1 gets executed after anim2. How does a simple + operator that?

anim1 = Animation(duration=1, center=(100,100) type='delta')
anim2 = Animation(duration=1, rotation=45 type='delta')

anim = anim1 + anim2

Upvotes: 2

Views: 200

Answers (3)

Paulo Scardine
Paulo Scardine

Reputation: 77261

This will call anim1.__add__(anim2).

In order to understand what is happening under the hood you have to inspect the definition of __add__ method from Animation class.

Upvotes: 8

Marc Demierre
Marc Demierre

Reputation: 1108

In Python, you can redefine the behavior of the mathematical operators. If I understood your question, Animation probably redefines the "+" operator using the __add__ method.

More info: Official Documentation

Upvotes: 3

user470379
user470379

Reputation: 4889

Check out the dis module. It has a function dis that will take a function/module/class and show you the byte code.

Upvotes: 0

Related Questions