Home >Backend Development >Python Tutorial >In Python, an object method is a function that can be executed on a specific object. These methods are typically used to manipulate and manage the state and behavior of objects
To return an empty object, use the object() method in Python. This is the basis of all classes. Let's look at the syntax of object(). Contains no parameters -
object()
Cannot add new properties or methods to this object. It itself serves as the base for all properties and methods, the default values for any class.
In this example, we will use the object() method to create an empty object -
# Create an empty object ob = object() # Display the empty object print("Object = ",ob)
Object = <object object at 0x7f2042320f00>
In this example, we will create an empty object using the object() method. We will display properties using dir() method -
# Create an empty object ob = object() print(dir(ob))
['__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__']
Let's see what happens when comparing two empty objects. They will return False -
# Create two objects ob1 = object() ob2 = object() # Comparing both then objects print("Are both the objects equal = ",str(ob1 == ob2))
Are both the objects equal = False
The above is the detailed content of In Python, an object method is a function that can be executed on a specific object. These methods are typically used to manipulate and manage the state and behavior of objects. For more information, please follow other related articles on the PHP Chinese website!