魔术方法

魔术方法

类别 方法名
可视化 __str__, __repr__, __format__, __bytes__
数值转换 __abs__, __bool__, __complex__, __int__, __float__, __hash__, __index__
容器模拟 __len__, __getitem__, __setitem__, __delitem__, __contains__.__misss__
迭代枚举 __iter__, __reversed__, __next__
可调用模拟 __call__
上下文管理 __enter__, __exit__
实例创建和销毁 __new__, __init__, __del__
属性管理(反射) __dir__, __getattr__, __setattr__, __delattr__, __getattribute__
属性描述符(描述器) __get__, __set__, __delete__
特殊属性 __name__, __module__, __class__, __bases__, __doc__, __mro__, __dir__
比较运算符 __eq__,__lt__, __le__, __gt__, __ge__, __ne__
算数运算符 __add__, __sub__, __mul__, __truediv__, __mod__, __floordiv__, __pow__, __divmod__
增量运算符 __iadd__, __isub__, __imul__, __itruediv__, __imod__, __ifloordiv__, __ipow__
反向运算符 __radd__, __rsub__
其他 __slots__

内置函数

内置函数名 方法名
数学运算 abs, divmod,max,min,pow, round, sum
类型转换 bool,int,float, complex, str, bytearray, bytes, memoryview, ord,chr, bin,oct,hex
序列操作 all, any, filter, map,next,reversed, sorted, zip
对象操作 help,dir,id,hash, type,len, ascii,format, vars,
反射操作 __import__, isinstance, issubclass, hasattr, getattr, setattr, delattr,callable
变量操作 globals, locals,
交互操作 print,input
文件操作 open
编译执行 compile, eval,exec, repr
装饰器 property,classmethod, staticmethod,
数据结构 tuple, list, dict, set,frozenset, enumerate, range,iter, slice,super, object

标识符:

1
2
3
4
5
6
7
False      await      else       import     pass
None break except in raise
True class finally is return
and continue for lambda try
as def from nonlocal while
assert del global not with
async elif if or yield

模块常用方法

内置模块 方法名
re compile, search, match, fullmatch,split,findall, sub,
string ascii_letters,ascii_lowercase.digits
datetime datetime
collections nametuple, deque, OrderdDict, defaultdict,
bisect bisect_left,bisect_right,
math ceil
random randint, choice, randrange,shuffle, sample
functools reduce, partial,lru_cache
pathlib
os
shutil copyfileobj, copyfile, copymode, copystat,copy,copy2,copytree,rmtree,move,
pickle
csv reader
time
threading
queue
json
base64
sys
inspect signature(callable)获取签名,
ConfigParser
argparse
heapq hea
感谢支持 !
0%