The Python object() function returns the empty object, and the Python object takes no parameters.
Syntax of Python object()
For versions of Python 3.x, the default situation. The base class for all classes, including user-defined ones, is the Python object class. As a result, in Python, all classes inherit from the Object class.
Syntax : obj = object()
Parameters :Â None
Returns : Object of featureless class. Acts as base for all object
Example of Python object()Â
In this case, the object() function was used to create a new object, and the type() and dir() methods were used to identify the object's characteristics. We can see from the results that obj is a part of the object class. We can also observe that there is no __dict__ attribute on obj. As a result, we are unable to give an instance of the object class attributes.
Python3
# declaring the object of class object
obj = object()
# printing its type
print("The type of object class object is: ")
print(type(obj))
# printing its attributes
print("The attributes of its class are: ")
print(dir(obj))
Output:Â
The type of object class object is :Â
The attributes of its class are :Â
['__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__']
Understanding the properties of an object() function in Python
Properties of the object() function in Python
- Objects of object class cannot add new attributes to it.
- These objects are uniquely made and do not equate to one other, i.e don't return true once compared.
- the object acts as a base class for all the custom objects that we make.
Example:
In this example, we will try to understand object equality, subclass functionality, and Python isinstance. In last, we will assign a new value to the obj1.a to see a new attribute value of a.
Python3
class example():
a = "Geeks"
# declaring the objects of class object
obj1 = demo()
obj2 = demo()
# checking for object equality
print("Is obj1 equal to obj2 : " + str(obj1 == obj2))
# checking for subclass
print("The Example class is a subclass of the object class? ", issubclass(example, object))
# checking for object instance
print("The obj1 is a instance of the object class? ", isinstance(obj1, object))
# trying to add attribute to object
print("Default attribute: ", obj1.a)
obj1.a = "GeeksforGeeks"
print("Assigning new attribute: ", obj1.a)
Output:Â
Is obj1 equal to obj2 : False
The Example class is a subclass of the object class? True
The obj1 is a instance of the object class? True
Default attribute: Geeks
Assigning new attribute: GeeksforGeeks
Similar Reads
Python next() method Python's next() function returns the next item of an iterator. Example Let us see a few examples to see how the next() method in Python works. Python3 l = [1, 2, 3] l_iter = iter(l) print(next(l_iter)) Output1 Note: The .next() method was a method for iterating over a sequence in Python 2.  It has
4 min read
Python | Method Overloading In many programming languages like C++ or Java, you can define multiple methods with the same name but different parameter lists. This concept is called method overloading.Python does not support method overloading by default. If you define multiple methods with the same name, only the latest defini
5 min read
classmethod() in Python The classmethod() is an inbuilt function in Python, which returns a class method for a given function. This means that classmethod() is a built-in Python function that transforms a regular method into a class method. When a method is defined using the @classmethod decorator (which internally calls c
8 min read
Python List methods Python list methods are built-in functions that allow us to perform various operations on lists, such as adding, removing, or modifying elements. In this article, weâll explore all Python list methods with a simple example.List MethodsLet's look at different list methods in Python:append(): Adds an
3 min read
Call Parent class method - Python In object-oriented programming in Python, the child class will inherit all the properties and methods of the parent class when the child class inherits the parent class. But there may be some cases when the child class has to call the methods of the parent class directly. Python has an easy and effe
5 min read