In Python, object is the base class of every class: ints, strings, lists, and your own classes all inherit from it, directly or indirectly. Calling object() creates a new, completely featureless instance.
A bare object() has no __dict__, so you cannot attach attributes to it. What it does have are the default methods every object inherits, such as __eq__, __hash__, __repr__, and __str__. Because each object() is unique, it is a popular sentinel value for “no argument given”.
object is a built-in type (a class) that you call like a function: each call creates a new object object. Like every built-in, it lives in the builtins module and is always available without an import.
Syntax
It takes no arguments.
python
marker = object()
Call
What it does
object()
A new, unique, empty object.
isinstance(x, object)
Always True.
object() == object()
False: equality defaults to identity.
class A: ...
Implicitly class A(object).
Printing a bare object shows its type and a memory address, which changes on every run; compare it with is instead of printing it.
Library declarations
python
object()
# class object: the root of the class hierarchy
Parameters
object() takes no arguments; passing any raises TypeError.
Return Value
Return Value
Description
object
A new featureless instance.
Python Examples
Example 1 — Every Class Inherits from object
Check that built-in types and your own classes all have object as their base.
python
class Point:
pass
print(issubclass(Point, object))
print(isinstance(42, object), isinstance("hi", object))
print(Point.__mro__[-1] is object)
print(type(object()).__name__)
Output
True
True True
True
object
How It Works
Implicit base.class Point: is the same as class Point(object):.
Everything is an object. Even 42 and "hi" are instances of object.
End of the MRO.object is always the last class in the method resolution order.
Type name, not the object. Printing type(...).__name__ avoids the address in the default repr.
Example 2 — A Bare object() Has No __dict__
Try to add an attribute to object(), then compare with an empty class.
python
plain = object()
try:
plain.name = "Ana"
except AttributeError:
print("object() instances cannot get new attributes")
print(hasattr(plain, "__dict__"))
class Empty:
pass
e = Empty()
e.name = "Ana"
print(e.__dict__)
Output
object() instances cannot get new attributes
False
{'name': 'Ana'}
How It Works
No storage.object() has no per-instance dictionary, so assignment raises AttributeError.
Check with hasattr.hasattr() confirms that __dict__ is missing.
Subclasses get a dict. Instances of a normal class, even an empty one, store attributes in __dict__.
Lightweight by design. Not having a dict keeps bare objects small, which suits sentinel markers.
Example 3 — Use object() as a "No Value" Marker
Tell “no default given” apart from None, and list some default methods.
python
_MISSING = object()
def lookup(data, key, default=_MISSING):
if key in data:
return data[key]
if default is _MISSING:
raise KeyError(key)
return default
print(lookup({"a": None}, "a"))
print(lookup({}, "b", 0))
print(object() == object(), _MISSING == _MISSING)
names = ("__eq__", "__hash__", "__repr__", "__str__")
print(sorted(n for n in dir(object) if n in names))