Python property() Function Syntax

Python property() function is used to create a class property in Python.

Syntax: property(fget, fset, fdel, doc)

Parameters: 

  • fget() – used to get the value of attribute
  • fset() – used to set the value of attribute
  • fdel() – used to delete the attribute value
  • doc() – string that contains the documentation (docstring) for the attribute

Return: Returns a property attribute from the given getter, setter and deleter.

Note:

  • If no arguments are given, property() method returns a base property attribute that doesn’t contain any getter, setter, or deleter.
  • If doc isn’t provided, property() method takes the docstring of the getter function.

Python property() function

Python property() function returns the object of the property class and it is used to create the property of a class.  In Python, the property() function is a built-in function that allows us to create a property for a class. In this article, we will learn more about the Python property() function.

Similar Reads

Python property() Function Syntax

Python property() function is used to create a class property in Python....

What is property() Function in Python

Python property() function is a built-in function that allows us to create a special type of attribute called a property for a class. Properties are used to encapsulate the access to an object attribute and to add some logic to the process such as computation, access control, or validation....

Python Property vs Attribute

...