python类内置函数列表

类的内置特殊函数列表

__init__(self[, args])              #类的构造函数
__del__(self)                       #类的析构函数
__repr__(self)                      #与eval()兼容的对象字符串表达式(用于实例重建)
__str__(self)                       #调用str()执行的函数
__cmp__(self)                       #比较两个实例,小于为负,等于为0,大于为正
__hash__(self)                      #hash code
__nonzero__(self)                   #self为逻辑假,返回0;否则返回1
__getattr__(self, name)             #使用self.name时调用
__setattr__(self, name, value)      #使用self.name=value时调用
__delattr__(self, name)             #调用del self.name时调用
__call__(self[, args])              #像使用函数一样使用类object(args),即object.__call__(self, args)

如果对象可通过序列或字典接口访问,则需要实现以下函数

__len__(self)                       #内置函数len()时调用
__getitem__(self, key)              #self[key]时调用
__setitem__(self. key, value)       #self[key] = value时调用
__delitem__(self, key)              #del self[key]时调用
__getslice__(self, i, j)            #self[i:j]
__setslice__(self, i, j, value)     #self[i:j]=value
__delslice__(self, i, j)            #del self[i:j]

重载运算符

__add__(self, other)
__sub__(self, other)
__mul__(self, other)
__div__(self, other)
__mod__(self, other)
__divmod__(self, other)
__pow__(self, other[, modulo])
__lshift__(self, other)
__rshift__(self, other)
__and__(self, other)
__or__(self, other)
__xor__(self, other)


转载于:https://my.oschina.net/u/1459779/blog/365239

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值