Menu Close

Python object() Function

In this article, we will go through the python object function to get the featureless object. After creating an object, you can not add properties and methods to that object. In previous tutorials, we have seen various python built-in functions along with examples.

Python object() function

Python object function is a built-in function that is used to returns the featureless object. Once you have created an empty object, you can not add properties and methods.

Syntax

The syntax of object function in python is:-

object()

Parameter

object function in Python does not support any parameter.

Return Value

The object() function return featureless object.

Python object example

Here we will see various examples to understand python object function.

Example 1:

x = object()
print(x)

Output:
<object object at 0x000002926D658190>

Example 2:

You can check the type of the x by using type() function.

x = object()
print(type(x))

Output will be:- <class ‘object’>

Example 3:

You can see all the attributes of object using python dir() function.

x = object()
print(dir(x))

Output:

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

Example 4:

If you try the add property in object, you will get an error.

x = object()
x.name = 'Programming Funda'

Output

Traceback (most recent call last):
  File "C:\Users\Vishvajit\Desktop\PF Article\Python Basic part1\test.py", line 2, in <module>
    x.name = 'Programming Funda'
AttributeError: 'object' object has no attribute 'name'

Conclusion

In this tutorial, you have learned all about the Python object function to create a featureless object.
If you like this article, please share it and keep visiting for further python built-in functions.

Python built-in functions


For more information:- Click Here

Python hex() Function
Python isinstance() Function

Related Posts