What does an object() method do in Python?


To return an empty object, the object() method is used in Python. This acts as a base for all the classes. Let’s see the syntax of object(). No parameter gets included −

object()

New properties or methods cannot be added to this object. This itself acts as a base for all properties and methods, default for any class.

Create an Empty Object

Example

In this example, we will create an empty object using the object() method −

# Create an empty object ob = object() # Display the empty object print("Object = ",ob)

Output

Object =  <object object at 0x7f2042320f00>

Create an Empty Object and display attributes

Example

In this example, we will create an empty object using the object() method. We will display the attributes using the dir() method −

# Create an empty object ob = object() print(dir(ob))

Output

['__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__']

Compare Two Empty Objects

Example

Let’s see what will happen when two empty objects are compared. They will return False −

# Create two objects ob1 = object() ob2 = object() # Comparing both then objects print("Are both the objects equal = ",str(ob1 == ob2))

Output

Are both the objects equal = False

Updated on: 16-Sep-2022

110 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements