0

I'm looking at the python documentation and came across 'type()' under the built-in-functions section. https://docs.python.org/3/library/functions.html

However, when I look at the actual details, I see it as a class which takes 1 or 3 arguments. https://docs.python.org/3/library/functions.html#type

>>> type(type)
<class 'type'>
>>> type(pow)
<class 'builtin_function_or_method'>

If it's not a function, why is it listed under builtin-functions section.? Am I missing something.?

user3170122
  • 677
  • 3
  • 9
  • 18
  • There're other built-in types listed on that page e.g. `list`, `dict`, etc. – vaultah Jan 13 '18 at 12:24
  • yeah, I think the question applies to them too.. – user3170122 Jan 13 '18 at 12:25
  • 1
    If you are interested in detailed description, have a look at [this answer](https://stackoverflow.com/a/6581949/5741172). It actually cover details about `metaclasses` but also explains the abilities of `type` and how it behaves in different situations. – Sohaib Farooqi Jan 13 '18 at 12:33

1 Answers1

0

Python has a number of objects that are callable. Some are used more like functions, even though they are actually classes or types. The distinction isn't really that important, more of an implementation detail.

For example, list() gives you a new list. That's because list is a type. But if you want to think of it as a function that makes lists, that's OK too.

Ned Batchelder
  • 364,293
  • 75
  • 561
  • 662
  • that makes sense to some extent..I agree that the distinction isn't important, but kinda curious on why it's listed under builtin functions.. – user3170122 Jan 21 '18 at 06:30
  • It's listed there because they don't have a section called builtin classes, and because they are mostly used as if they were functions. – Ned Batchelder Jan 21 '18 at 12:41