[英]Python - Why are classes listed in the list of built-in functions?
The Python docs lists property() as a built-in function . Python文档将property()列为内置函数 。
However, the function description has the keyword "class" in front of it in the docs. 但是,函数描述在docs中有前面的关键字“class”。
class property (fget=None, fset=None, fdel=None, doc=None) class 属性 (fget = None,fset = None,fdel = None,doc = None)
This also happens with 这也发生在
class set ([iterable]) 类 集 ([iterable])
and 和
class slice (stop) 类 切片 (停止)
What does this mean? 这是什么意思? - why are classes listed under built-in functions. - 为什么类在内置函数下列出。 Is this just a documentation issue or is there a technical reason? 这只是一个文档问题还是有技术原因?
EDIT: I am not asking about how property() works. 编辑:我不是在询问property()的工作原理。
The Python glossary defines a function as: Python术语表将函数定义为:
A series of statements which returns some value to a caller. 一系列语句,它们向调用者返回一些值。 It can also be passed zero or more arguments which may be used in the execution of the body. 它也可以传递零个或多个参数,这些参数可以用于执行正文。
A class can be passed arguments, and returns a value to the caller, so arguably by this definition classes are functions*. 一个类可以传递参数,并向调用者返回一个值,因此可以说这个定义类是函数*。
In addition (as deceze points out in the comments), a class should always return an instance of itself – set
, property
, slice
, etc. all return instances of set
, property
, slice
, etc. respectively – so set
, property
and friends are all also classes, and so they are documented as such: 另外(如deceze在评论中指出的),一类应该总是返回自己的一个实例- set
, property
, slice
,等的所有返回实例set
, property
, slice
等分别-如此set
, property
和朋友都是一些类,因此它们被记录为这样的:
class set ([ iterable ]) 类 集 ([ iterable ])
meaning that set
is a class, not that it returns one. 意思是set
是一个类,而不是它返回一个。
I would guess that set
etc. are documented in the "built-in functions" page because a) they are callable, and b) it's convenient to have all the documentation for "things you can call" in one place. 我猜这个set
等都记录在“内置函数”页面中,因为a)它们是可调用的,并且b)在一个地方拥有“你可以调用的东西”的所有文档很方便。
*Strictly speaking, isinstance(C, types.FunctionType)
is false for any class C
(as far as I can tell), but classes are certainly callables ( isinstance(C, typing.Callable)
is true), which is maybe a more useful property to think about. *严格地说, isinstance(C, types.FunctionType)
对于任何类C
都是假的(据我所知),但类肯定是callables( isinstance(C, typing.Callable)
是真的),这可能是更多有用的财产要考虑。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.