Python object()

The syntax of object() is:

o = object()

object() Parameters

The object() function doesn't accept any parameters.


Return Value from object()

The object() function returns a featureless object.


Example: How object() works?

test = object()

print(type(test))
print(dir(test))

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

Here, an object test is created.

In the program, we have used type() to get the type of the object.

Similarly, we have used dir() to get all the attributes. These attributes (properties and methods) are common to instances of all Python classes.


Also Read:

Did you find this article helpful?

Our premium learning platform, created with over a decade of experience and thousands of feedbacks.

Learn and improve your coding skills like never before.

Try Programiz PRO
  • Interactive Courses
  • Certificates
  • AI Help
  • 2000+ Challenges