object()
object() Returns:
object · Added in v3.0 · Updated March 13, 2026 · Built-in Functions base-class builtin oop inheritance
object() is the base class from which all other classes inherit in Python. Every class in Python implicitly inherits from object unless it specifies a different base class. This makes object the root of Python’s class hierarchy.
Syntax
object()
Parameters
object() takes no parameters. It creates a new instance of the base object class.
Examples
Basic usage
# Create a basic object instance
obj = object()
print(obj) # <object object at 0x7f7f9c5e8b80>
print(type(obj)) # <class 'object'>
Checking inheritance
Every class implicitly inherits from object:
class MyClass:
pass
print(isinstance(MyClass(), object)) # True
print(issubclass(MyClass, object)) # True
print(issubclass(object, object)) # True
Default methods from object
All Python objects have these methods inherited from object:
obj = object()
# __repr__ - official string representation
print(repr(obj)) # <object object at 0x7f7f9c5e8b80>
# __str__ - informal string representation
print(str(obj)) # <object object at 0x7f7f9c5e8b80>
# __hash__ - hash value for use in sets/dicts
print(hash(obj)) # 8767552312507
# __eq__ - equality comparison
print(obj == object()) # False (different identity)
# __ne__ - inequality comparison
print(obj != object()) # True
Customizing with inheritance
When you define a class, it inherits all object methods, which you can override:
class Person:
def __init__(self, name):
self.name = name
def __repr__(self):
return f"Person({self.name!r})"
def __str__(self):
return self.name
p = Person("Alice")
print(repr(p)) # Person('Alice')
print(str(p)) # Alice
Common Patterns
Checking if something is a basic object
def is_plain_object(x):
"""Check if x is the base object class or instance."""
return type(x) is object or x is object
print(is_plain_object(object())) # True
print(is_plain_object(object)) # True
print(is_plain_object("hello")) # False
Using object as a placeholder
# Sentinel value when you need a unique marker
NO_VALUE = object()
def get_value(key, default=NO_VALUE):
# Implementation using sentinel
pass
Errors
object() itself raises no errors, but attempting to call certain methods on instances that don’t implement them can cause issues:
# Trying to call non-existent attributes raises AttributeError
obj = object()
obj.custom_attribute # AttributeError: 'object' has no attribute 'custom_attribute'