The Python docs lists property() as a built-in function.
However, the function description has the keyword "class" in front of it in the docs.
class property(fget=None, fset=None, fdel=None, doc=None)
This also happens with
class set([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.
list is a built-in class in Python. However, classes are callable just like functions, and when called, classes instantiate and return objects, so you can pass a class as an argument where a function (or a callable to be precise) is expected.
Compares elements of both lists. Returns item from the list with max value. Returns item from the list with min value. Converts a tuple into list.
Python any() The any() function returns True if any element of an iterable is True . If not, it returns False .
The Python glossary defines a function as:
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:
class set([iterable])
meaning that set
is a class, not that it returns one.
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.
*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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With