Skip to main content

Python object() Function

The object() function returns a new empty object.

Syntax

object()

object() Parameters

Python object() function has no parameters.

object() Return Value

Python object() function returns a new instance of the base class, which is essentially an empty object with no attributes or methods. This object acts as a base for all object instances in Python.

Examples

Example 1: Creating and Using an Empty Object

obj = object()

# Checking the type of the object
print(type(obj)) # Output: <class 'object'>

output

<class 'object'>

Example 2: Using object() as a Base Class

class MyEmptyClass:
pass

# The above class is implicitly inheriting from `object`
obj_instance = MyEmptyClass()

print(isinstance(obj_instance, object)) # Output: True

output

True

Example 3: Get all attributes of an Empty Object created with object()

test = object()

print(type(test))
print(dir(test))

output

<class 'object'>
['__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__']