Python 3 reference · Built-in Functions
Python object() Function
Return a new featureless object. object is the base class of every Python class and provides the default methods.
Python 3 Since 3.0
Syntax
object()
Return value
A new, unique object instance.
Examples
class Point: # implicitly inherits from object
pass
print(Point.__mro__)
print(isinstance(42, object))
Output
(<class 'Point'>, <class 'object'>) True
MISSING = object() # a unique marker value
def get(d, key, default=MISSING):
if key in d:
return d[key]
if default is MISSING:
raise KeyError(key)
return default
print(get({"a": 1}, "b", None))
Output
None
Good to know
Plain object() instances can't have attributes (object().x = 1 fails). In Python 3.15 and later, the
sentinel() built-in is a clearer way to create marker values.
Version history
| Version | Change |
|---|---|
| Python 3.0 | Added |
Related
sentinel()· Create a unique, named marker value (new in Python 3.15), such as MISSING, to tell 'no value given' apart from None.type()· With one argument, return an object's type. With three arguments, create a new class dynamically.super()· Return a proxy that calls methods of the parent class, so a subclass can extend a method instead of replacing it.isinstance()· Return True if an object is an instance of a class, one of its subclasses, or any class in a tuple or union of classes.- Python Classes and Objects · tutorial