Python object()

Filed Under: Python

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.

obj = object()





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

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.

obj.i = 10 


AttributeError: 'object' object has no attribute 'i'
You can checkout complete python script and more Python examples from our GitHub Repository.

Reference: Official Documentation

Leave a Reply

Your email address will not be published. Required fields are marked *

Generic selectors
Exact matches only
Search in title
Search in content