Section 4.7. Type Factory Functions


4.7. Type Factory Functions

Since Python 2.2 with the unification of types and classes, all of the built-in types are now classes, and with that, all of the "conversion" built-in functions like int(), type(), list(), etc., are now factory functions. This means that although they look and act somewhat like functions, they are actually class names, and when you call one, you are actually instantiating an instance of that type, like a factory producing a good.

The following familiar factory functions were formerly built-in functions:

  • int(), long(), float(), complex()

  • str(), unicode(), basestring()

  • list(), tuple()

  • type()

Other types that did not have factory functions now do. In addition, factory functions have been added for completely new types that support the new-style classes. The following is a list of both types of factory functions:

  • dict()

  • bool()

  • set(), frozenset()

  • object()

  • classmethod()

  • staticmethod()

  • super()

  • property()

  • file()



Core Python Programming
Core Python Programming (2nd Edition)
ISBN: 0132269937
EAN: 2147483647
Year: 2004
Pages: 334
Authors: Wesley J Chun

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net