overview of object()
The object() function returns a new instance of the object class. Every object created by the object() function is always unique. The created object has common dunder methods, but it is not possible to assign arbitrary attributes.
use of object() function
The object() function is used to create new objects as shown below.
# use of object() function
newObject = object()
print(dir(newObject))
The new object is initiated and assigned to the variable newObject. Then, the dir() function is used, to return all valid attributes of the newly created 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__']
Each and every object created by the object() function is unique.
# object() creates unique objects
object1 = object()
object2 = object()
object1 == object2
Two objects are created and assigned to the variables object1 and object2. Then, it is checked if object1 is the same as object2. This check returns False, which proves that the objects are unique.
False
syntax of object()
The syntax of the object() function is:
object()
arguments of object()
The object() function doesn't accept any arguments.
If any argument is given, a TypeError exception is raised.
TypeError: object() takes no arguments
return value of object()
The object() function returns the newly created object. If more than one object is created, each of the returned objects is unique.