__bases__
A class attribute holding the tuple of the class's direct parent classes.
In more detail
__bases__ lists only the direct parents, in the order the class statement gives them, and a class with no listed parent has (object,). Classes also carry __name__, their name as a string, and __module__, the name of the module that defined them, which is '__main__' for the running script. __mro__ is the full search order, the class first and object last.
Example
class A: pass
class B(A): pass
print(B.__bases__, B.__module__) # (<class '__main__.A'>,) __main__Related terms
- introspection — A program examining objects and classes at run time, for example with hasattr, getattr, type and isinstance.
- inheritance — Declaring one class or type as a specialised version of another, so it receives the parent's members and can be used wherever the parent is expected.
- method resolution order — The order in which Python searches a class and its parents for a method or attribute.
Taught in
- Exception Classes Of Your Own — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Introspection: hasattr, __name__, __module__ And __bases__ — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Multiple Inheritance, The MRO And Diamonds — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Object-Oriented Sprint — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Mock, Review And Exam Day — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep