Python object() function returns a new featureless object. Python is an object-oriented programming language and object
is the base of all the classes.
Python object()
Python object() function doesn’t accept any argument. Since it returns a new instance of an object, all its methods are present in other classes too.
There is hardly any practical use to call this function since it’s featureless. The object instance returned doesn’t have a __dict__
dictionary, so we can’t assign any arbitrary attributes to it.
1 2 3 4 5 6 |
obj = object() print(type(obj)) print(dir(obj)) print(obj.__hash__()) |
Output:
1 2 3 4 5 |
<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__'] 270490892 |
Notice that dir() function output doesn’t have __dict__ as an attribute.
Let’s see what happens when we try to assign an attribute to this object instance.
1 2 3 |
obj.i = 10 |
Output:
1 2 3 |
AttributeError: 'object' object has no attribute 'i' |
Reference: Official Documentation