object() Function in Python:
The function object() returns an empty object.
This object cannot be extended with new properties or methods.
This object serves as the foundation for all classes; it contains the built-in properties and methods that are the default for all classes.
Syntax:
object()
Parameters: This function has no Parameters.
Return Value:
The object() function returns an object with no features.
object() Function with Examples in Python
Method #1: Using Built-in Functions (Static Input)
Approach:
- Take a variable and initialize it with the object() function.
- Pass the above result as an argument to the type() function to get the type of the above object.
- Store it in a variable.
- Pass the above result as an argument to the dir() function to get all the attributes.
- Store it in another variable.
- Print the type of the result object.
- Print all the attributes (dir) of the result object.
- The Exit of the Program.
Below is the implementation:
# Take a variable and initialize it with the object() function. m = object() # Pass the above result as an argument to the type() function to get the type # of the above object. # Store it in a variable. obj_type = type(m) # Pass the above result as an argument to the dir() function to get all the # attributes. # Store it in another variable. obj_dir = dir(m) # Print the type of the result object. print(obj_type) # Print all the attributes (dir) of the result object. print(obj_dir)
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__']
An object m is created here.
We used type() in the program to determine the type of the object.
Similarly, we used dir() to retrieve all of the attributes. These attributes (properties and methods) are shared by all Python class instances.