Python str () function is not actually a function?

I got the impression that something seems to be str(5)calling a function strfor an integer 5. But when you enter strinto the interpreter:

>>> str
<class 'str'>

So, str- this is really a class that makes type code if type(a) is strmore understandable. But then why stris it listed in the "Built-in Functions" section of the docs? Is this just a simplification?

+4
source share
3 answers

Listing this as a function makes it a bit easier, yes. But remember that classes are called * - the way you create an instance of a class!

If this helps you, consider str(5)how to build a string from a number 5.

, : int(), float(), str(), tuple(), list(), set(), file()... " re , , .

*: , .

+10

str(5) __call__() str:

>>> str(5)
'5'
>>> str.__call__(5)
'5'

, , str , ( 2.7)

+1

, - , str() str.

0

Source: https://habr.com/ru/post/1536884/


All Articles