开发者

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开发者_JAVA技巧


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.


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜