1

I noticed Python comes with built-in methods such as .upper() or lower() and these two are part of the string object.

"a string".upper()
"A STRING".lower()

What confuses me is that some functions are not called on an object, for example the function type

type("a string")

So in this case, is "type" considered a method or just a stand-alone function which is built into the language?

Zoltan King
  • 1,964
  • 4
  • 18
  • 38
  • 2
    `type()` is not specific to a type, it is a function that can handle *any of Python's objects*. – Martijn Pieters Mar 11 '19 at 17:02
  • `type` might not be the best example, since `type(type)` show's that type's type is ``, rather than something like "function" or "method". Maybe look at `len` or `max` when trying to puzzle out the behavior of built-in functions. – Kevin Mar 11 '19 at 17:02
  • I think, this is the answer you are looking for http://effbot.org/pyfaq/why-does-python-use-methods-for-some-functionality-e-g-list-index-but-functions-for-other-e-g-len-list.htm – han solo Mar 11 '19 at 17:06
  • The distinction here is that `type` is a *type*, and types are also callable. – chepner Mar 11 '19 at 17:07

0 Answers0