Built-in Attributes

Some objects export special attributes that are predefined by Python. The following is a partial list because many types have unique attributes all their own; see the entries for specific types in the Python Library Reference.[6]


Dictionary used to store object X’s writable attributes.


Class object from which instance I was generated. In version 2.2 and later, this also applies to object types; most objects have a __class__ attribute (e.g., [].__class__ == list == type([])).


Tuple of class C’s base classes, as listed in C’s class statement header.


Object X’s name as a string; for classes, the name in the statement header; for modules, the name as used in imports, or "__main__" for the module at the top level of a program (e.g., the main file run to launch a program).

[6] As of Python 2.1, you can also attach arbitrary user-defined attributes to function objects, simply by assigning them values. Python 2.X also supports special attributes I.__methods__ and I.__members__: lists of method and data member names for instances of some built-in types. These are removed in Python 3; use the built-in dir() function.

Get Python Pocket Reference, 4th Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.