The object () function in Python

Continuing with the topic of built-in functions in Python, the article will introduce you to the object () function with syntax, usage as well as specific examples. Invites you to read the track.

The object () function in Python returns an empty object. You cannot add new properties or methods to this object. This return object is the basis for all classes, and contains default built-in properties and methods for all classes.

The syntax of the object () function in Python:

 o = object() 

Parameters of the object () function

The object () function contains no parameters.

The value returned from object ()

The object () function returns an empty object, the object has no features (Featureless Object).

Example 1: how does object () work?

 test = object() print(type(test)) print(dir(test)) 

When you run the program, the output will be:

  ['__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__'] 

In the above code, we create the test object and use the built-in functions type () and dir () to get the object's valid types and properties. The result has no __dict__ in the output. Therefore, you cannot assign arbitrary properties to instances of this class.

See also: Python built-in functions

4.5 ★ | 2 Vote

May be interested

  • Getattr () function in PythonGetattr () function in Python
    the getattr () function in python returns the value of the property you want to find, if the object does not have this property the function will return the default value provided.
  • The delattr () function in PythonThe delattr () function in Python
    the delattr () function in python is used to delete an attribute from the specified object. how does the delattr () function have a syntax, what parameters do you have, please find out in quantrimang in this section.
  • Callable () function in PythonCallable () function in Python
    callable () in python checks whether objects can be called. if the object is allowed to call, the function returns true, otherwise it returns false. how does the callable () function have the syntax, what parameters do we have, we will learn in this section.
  • Issubclass () function in PythonIssubclass () function in Python
    the issubclass () function is built into python to check if an object is a subclass of classinfo.
  • Enumerate () function in PythonEnumerate () function in Python
    in python, the enumerate () function adds a counter before each iterable and returns the result as an enumerate object. the article will elaborate on the syntax, parameters and usage of the function. invites you to read the track.
  • Object-oriented programming in PythonObject-oriented programming in Python
    python is a powerful object-oriented programming language. therefore, creating and using objects is very easy. this article will introduce some basic concepts in object-oriented programming, as well as how to create and use them.
  • Learn Class and Object in PythonLearn Class and Object in Python
    python is an object-oriented programming language. unlike procedural programming, which emphasizes functions, object-oriented programming focuses on objects. this article quantrimang will explore class and object in depth, inviting readers to follow.
  • Type () function in PythonType () function in Python
    the built-in function type () in python returns the type of object passed as parameter.
  • Max () function in PythonMax () function in Python
    python's built-in max () function returns the largest element in an iterable or the largest of the passed parameters
  • Function open () in PythonFunction open () in Python
    the open () function is built into python to use to open a file and return the corresponding file object. follow the article to learn more about the syntax, parameters and usage of open ()