python/docs-pdf/library.pdf
The full list of supported magic methods is:
•__hash__,__sizeof__,__repr__and__str__
•__dir__,__format__and__subclasses__
•__round__,__floor__,__trunc__and__ceil__
•Comparisons:__lt__,__gt__,__le__,__ge__,__eq__and__ne__
•Container methods:__getitem__,__setitem__,__delitem__,
__contains__,__len__,__iter__,__reversed__and__missing__
•Context manager:__enter__,__exit__,__aenter__and__aexit__
•Unary numeric methods:__neg__,__pos__and__invert__
•The numeric methods (including right hand and in-place variants):
__add__,__sub__,__mul__,__matmul__,__div__,__truediv__,
__floordiv__,__mod__,__divmod__,__lshift__,__rshift__,
__and__,__xor__,__or__, and__pow__
•Numeric conversion methods:__complex__,__int__,__float__and__index__
•Descriptor methods:__get__,__set__and__delete__
•Pickling:__reduce__,__reduce_ex__,__getinitargs__,
__getnewargs__,__getstate__and__setstate__
•File system path representation:__fspath__
•Asynchronous iteration methods:__aiter__and__anext__
在3.8版更改: Added support foros.PathLike.__fspath__().
在3.8版更改: Added support for__aenter__,__aexit__,__aiter__and__anext__.
The following methods exist but arenotsupported as they are either in use by mock,
can’t be set dynamically, or cancause problems:
•__getattr__,__setattr__,__init__and__new__
•__prepare__,__instancecheck__,__subclasscheck__,__del__
4.6序列类型—list,tuple,range
4.6.1通用序列操作
4.6.3可变序列类型
我使用help()的方法查看文档,但是有的文档漏写解释,有的干脆直接漏写函数方法,于是就取看官方文档。
例如tuple.getnewargs(self, /)的解释,tuple.sizeof(self, /)这个就没写。
In [1]: print(dir({}))
['__class__', '__contains__', '__delattr__', '__delitem__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'clear', 'copy', 'fromkeys', 'get', 'items', 'keys', 'pop', 'popitem', 'setdefault', 'update', 'values']