Python's str() function not actually a function?

python

Solution

Listing it as a function is a bit of a simplification, yes. But remember that classes are callable* — that's how you create an instance of a class!

If it helps you any, think of `str(5)` as constructing a string from the number `5`.

Note that all of the other built-in types exist the same way: `int()`, `float()`, `str()`, `tuple()`, `list()`, `set()`, `file()`... they're all classes, but they can be called to construct an instance of their class, and will usually accept an instance of another type as an argument if it's applicable.

*: At least, most of the time.

Problem

I was under the impression that something like `str(5)` is calling the `str` function on the integer `5`. But when you type `str` into the interpreter: ``` >>> str <class 'str'> ``` So `str` is actually a class, which makes code like `if type(a) is str` make more sense. But then why is `str` listed under "Built-in Functions" in the docs? Is this just a simplification?

Original source

Related problems