python槽,python常用内置函数

常用邪术函数(非数学运算类型)

字符串示意

__repr__

__str__

聚集序列相关

__len__

__getitem__

__setitem__

__delitem__

__contains__

迭代相关

__iter__

__next__

可挪用

__call__

with上下文管理器

__enter__

__exit__

数值转换

__abs__

__bool__

__int__

__float__

__hash__

__index__

元类相关

__new__

__init__

属性相关

__getattr__

__setattr__

__getattribute__

__setattribute__

__dir__

属性描述符

__get__

__set__

__delete__

协程

__await__

__aiter__

__anext__

__aenter__

__aexit__

常用邪术函数(数学运算类型)

一元运算符

__neg__(-)

__pos__(+)

__abs__

二元运算符

__lt__(

__le__ <=

__eq__ ==

__ne__ !=

__gt__ >

__ge__ >=

算术运算符

__add__ +

__sub__ –

__mul__ *

__truediv__ /

__floordiv__ //

__mod__ %

__divmod__ 或 divmod()

__pow__ 或 ** 或 pow()

__round__ 或 round()

反向算术运算符

__radd__

__rsub__

__rmul__

__rtruediv__

__rfloordiv__

__rmod__

__rdivmod__

__rpow__

增量赋值算术运算符

__iadd__

__isub__

__imul__

__itruediv__

__ifloordiv__

__imod__

__ipow__

位运算符

__invert__ ~

__lshift__ <<

__rshift__ >>

__and__ &

__or__ |

__xor__ ^

反向位运算符

__rlshift__

__rrshift__

__rand__

__rxor__

__ror__

增量赋值位运算符

__ilshift__

__irshift__

__iand__

__ixor__

__ior__

调试工具

notebook

首先使用pip install -i https://douban.com/simple notebook安装然后运行ipython notebook

字符串示意

__str__

在打印一个实例化工具的时刻, python默认会挪用str(工具), 对应的邪术函数是__str__

class Company(object):

def __init__(self, employee__list):

self.employee = employee__list

company = Company(["tom", "bob", "jane"])

print(company)

print(str(company))

__repr__

__repr__是在开发模式下挪用的

class Company(object):

def __init__(self, employee__list):

self.employee = employee__list

company = Company(["tom", "bob", "jane"])

print(company)

company

再次强调, __repr__不是由于该类继续了某一个工具才能去写这个方式, 邪术函数可以写到任何一个界说的类中去, 然后python注释器就是识别出这个工具有该特征, 然后再调试模式下company会被注释器转换为repr(company), 然后再去挪用company.__repr__().

class Company(object):

def __init__(self, employee__list):

self.employee = employee__list

def __str__(self):

return ','.join(self.employee)

def __repr__(self):

return '.'.join(self.employee)

company = Company(["tom", "bob", "jane"])

print(company) # str 输出

company # repr输出

tom,bob,jane # 打印工具

tom.bob.jane # 调试模式

原文链接:https://www.cnblogs.com/wangbaojun/p/12858941.html

本站声明:网站内容来源于网络,若有侵权,请联系我们,我们将及时处理。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值