- 论坛徽章:
- 0
|
__init__(self,...) 这个方法在新建对象恰好要被返回使用之前被调用。
__del__(self) 恰好在对象要被删除之前调用。
__str__(self) 在我们对对象使用print语句或是使用str()的时候调用。
__lt__(self,other) 当使用 小于 运算符()的时候调用。类似地,对于所有的运算符(+,>等等)都有特殊的方法。
__getitem__(self,key) 使用x[key]索引操作符的时候调用。
__len__(self) 对序列对象使用内建的len()函数的时候调用。
__repr__(s) repr() and `...` conversions
__cmp__(s, o) Compares s to o and returns 0, 0, or >0. Implements >, , == etc...
__hash__(s) Compute a 32 bit hash code; hash() and dictionary ops
__nonzero__(s) Returns 0 or 1 for truth value testing
__getattr__(s, name) called when attr lookup doesn't find
__setattr__(s, name, val) called when setting an attr(inside, don't use "self.name = value"
![]()
use "self.__dict__[name] = val")
__delattr__(s, name) called to delete attr name>
__call__(self, *args) called when an instance is called as function.
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/18391/showart_505941.html |
|