__bases__Easy Examples

Tuple of base classes of a class

Accessing __bases__

How to access and use __bases__.

python
# __bases__ holds direct parent classes
class Animal:
    pass

class Dog(Animal):
    pass

print(Dog.__bases__)
print(int.__bases__)
print(bool.__bases__)

__bases__ is a special attribute that tuple of base classes of a class.

__bases__ in practice

Using __bases__ in everyday code.

python
# More __bases__ examples
print("__bases__ is a special Python attribute")

# Every object has certain dunder attributes
obj = object()
attrs = [a for a in dir(obj) if a.startswith("__")]
print(f"object has {len(attrs)} dunder attributes")

Understanding __bases__ helps you introspect and debug Python objects.

Want to try these examples interactively?

Open Easy Playground