In python, each variable to which we assign a value/container is treated as an object.
Object in itself is a class. Let’s discuss the properties and demonstration of how this class can be utilized for day-day programming.
Syntax : object() Parameters : None Returns : Object of featureless class. Acts as base for all object
Code #1 : Demonstrating working of object()
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__’]
- 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.
- object acts as a base class for all the custom objects that we make.
Code #2 : Demonstrating properties of object()
Is obj1 equal to obj2 : False
Traceback (most recent call last): File "/home/46b67ee266145958c7cc22d9ee0ae759.py", line 12, in obj1.name = "GeeksforGeeks" AttributeError: 'object' object has no attribute 'name'
- Object Oriented Programming in Python | Set 2 (Data Hiding and Object Printing)
- Object Oriented Programming in Python | Set 1 (Class, Object and Members)
- Python Object Comparison : "is" vs "=="
- Python | Check if a given object is list or not
- pickle — Python object serialization
- Python | Matplotlib Sub plotting using object oriented API
- Python | Convert dictionary object into string
- marshal — Internal Python object serialization
- Python __iter__() and __next__() | Converting an object into an iterator
- Data type Object (dtype) in NumPy Python
- Python | Ways to convert string to json object
- OOP in Python | Set 3 (Inheritance, examples of object, issubclass and super)
- Python | dtype object length of Numpy array of strings
- class method vs static method in Python
- Python | next() method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.