python 的对象内建方法:__XXX__(a1,a2)

文档:Customizing attribute access

The following methods can be defined to customize the meaning of attribute access (use of, assignment to, or deletion of x.name) for class instances.

在对该类对象做某种特定操作时,会触发相应方法的调用。

如 a+b=>__add__(b)

a[b] = 1=>__setitem__(1)

posted @ 2015-08-31 14:45  shinymood  阅读(347)  评论(0)    收藏  举报