类像str或type
>>> type("pear")
<class 'str'>
>>> type(str)
<class 'type'>
可以在 Python 中访问:
>>> str
<class 'str'>
>>> type
<class 'type'>
然而,类function和builtin_function_or_method不是。
>>> def foo(): pass
...
>>> type(foo)
<class 'function'>
>>> type(print)
<class 'builtin_function_or_method'>
它们显示为内置类,但尝试访问它们会引发名称错误:
>>> function
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'function' is not defined
>>> builtin_function_or_method
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'builtin_function_or_method' is not defined
有什么特别的function和builtin_function_or_method?
炎炎设计
慕妹3146593
相关分类