Category: 3. Property
-
Python Delete Property
Summary: in this tutorial, you’ll learn how to use the property() class to delete the property of an object. To create a property of a class, you use the @property decorator. Underhood, the @property decorator uses the property class that has three methods: setter, getter, and deleter. By using the deleter, you can delete a property from an object. Notice that the deleter() method…
-
Python Readonly Property
Summary: in this tutorial, you’ll learn how to define Python readonly property and how to use it to define computed properties. Introduction to the Python readonly property To define a readonly property, you need to create a property with only the getter. However, it is not truly read-only because you can always access the underlying attribute…
-
Python Property Decorator
Summary: in this tutorial, you’ll learn about Python property decorator (@property) and more importantly how it works. Introduction to the Python property decorator In the previous tutorial, you learned how to use the property class to add a property to a class. Here’s the syntax of the property class: The following defines a Person class with two attributes name and age: To define a…
-
Python Property
Summary: in this tutorial, you’ll learn about the Python property class and how to use it to define properties for a class. Introduction to class properties The following defines a Person class that has two attributes name and age, and create a new instance of the Person class: Since age is the instance attribute of the Person class, you can assign it a new value like this: The following assignment is also…