Python - Why are classes listed in the list of built-in functions?

Python docs list property () as an inline function .

However, the description function has the keyword "class" before it in the documents.

class property (fget = None, fset = None, fdel = None, doc = None)

It also happens with

class set ([iterable])

and

slice class (stop)

What does it mean? - why classes are listed in built-in functions. Is this just a problem with the documentation or is there a technical reason?

EDIT: I am not asking about how property () works.

+7
python
source share
1 answer

The Python Glossary defines a function as:

A series of statements that return a specific value to the caller. It can also be passed zero or more arguments that can be used when executing the body.

The class can be passed to the arguments and returns the value to the caller, so perhaps the * functions are probably the definition class.

In addition (as indicated in the comments in the comment), the class should always return an instance of itself - set , property , slice , etc. all return instances of set , property , slice , etc., respectively, are set , property , and friends are also classes, and therefore they are documented as such:

class set ([iterable])

means set is a class, not the one it returns.

I would suggest that set , etc. the built-in functions page is documented 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 C class (as far as I can tell), but the classes are certainly callable ( isinstance(C, typing.Callable) is true), which is possibly a more useful property to think about.

+3
source share

All Articles