Why built in functions are defined as class? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Why built in functions are defined as class? (/thread-35151.html) |
Why built in functions are defined as class? - quazirfan - Oct-04-2021 In python official documentation there is a list of built in functions. But if I click on some of them, instead of taking me to a function definition, it takes me to a class definition. But if they are classes, then why they are under function definition? For example, if I click on slice() function, it takes me to class slice
RE: Why built in functions are defined as class? - nadapez - Oct-04-2021 Quote:Built-in Functions The title is missleading. Some are not functions but types. Only that they are lowercase. To see if a builtin is a class or a function that just type the name of it without parenthesis. RE: Why built in functions are defined as class? - Larz60+ - Oct-05-2021 look at it this way abs is a class of type builtin_function_or_method, abs(14) is an instance of class abs with attribute 14 >>> type(abs) <class 'builtin_function_or_method'> >>>type(abs(14)) # returns type of instance of abs (which is of class int) <class 'int'> RE: Why built in functions are defined as class? - nadapez - Oct-08-2021 (Oct-05-2021, 02:42 AM)Larz60+ Wrote: look at it this way No, no! That's totally wrong!! abs is not a class. The type of abs is a class. Anyhow, to see if a builtin is a class or not, you dont need to use type. Just write the name of the builtin and press enter. >>> bytearray <class 'bytearray'>so bytearray is a class >>> abs <built-in function abs>so abs is a builtin function RE: Why built in functions are defined as class? - quazirfan - Oct-22-2021 (Oct-05-2021, 02:42 AM)Larz60+ Wrote: >>>type(abs(14)) # returns type of instance of abs (which is of class int) From abs() documentation, abs(x) Return the absolute value of a number. I think it is not correct to say instance of abs as abs function returns a number, or int in this case.
RE: Why built in functions are defined as class? - Gribouillis - Oct-23-2021 They should be called built-in callables instead of built-in functions. |