Sobes.tech
Junior — Middle

In what case will a class created in Python inherit from 'object' if no parent is explicitly specified?

sobes.tech AI

Answer from AI

In Python 3, all classes by default inherit from the base class object, unless another parent is explicitly specified. This means that a class without an explicit parent is called a "new-style" class.

Example:

class MyClass:
    pass

print(issubclass(MyClass, object))  # Outputs: True

In Python 2, the behavior was different: if a class did not explicitly inherit from object, it was considered an old-style class. In Python 3, all classes automatically inherit from object, ensuring consistency and access to modern language features.