例如,特殊方法(在Django中):
def __wrapper__
def __deepcopy__
def __mod__
def __cmp__
Run Code Online (Sandbox Code Playgroud)
要打印Python的保留字只需使用
>>> import keyword
>>> print(keyword.kwlist)
['False', 'None', 'True', 'and', 'as', 'assert', 'break', 'class', 'continue',
'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global',
'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass',
'raise', 'return', 'try', 'while', 'with', 'yield']
Run Code Online (Sandbox Code Playgroud)
要阅读Python特殊对象方法的说明,请阅读手册或Dive into Python.
你可以使用的另一个片段是
>>> [method for method in dir(str) if method[:2]=='__']
['__add__', '__class__', '__contains__', '__delattr__', '__doc__',
'__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__',
'__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__', '__le__',
'__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__',
'__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__',
'__sizeof__', '__str__', '__subclasshook__']
Run Code Online (Sandbox Code Playgroud)
查看str该类的所有内置特殊方法.
| 归档时间: |
|
| 查看次数: |
3741 次 |
| 最近记录: |