Vue3 Tutorial
Vue2 Tutorial
Bootstrap3
Bootstrap4
Bootstrap5
Machine Learning
PyTorch
TensorFlow
Sklearn
NLP
AI Agent
Ollama
Coding Plan
Python 3 Tutorial
- Python3 Tutorial
- Python3 Introduction
- Python3 Environment Setup
- Python3 VScode
- Python3 Basic Syntax
- Python3 Basic Data Types
- Python3 Data Type Conversion
- Python3 Interpreter
- Python3 Comments
- Python3 Operators
- Python3 Number
- Python3 String
- Python3 List
- Python3 Tuple
- Python3 Dictionary
- Python3 Set
- Python3 Conditional Control
- Python3 Loop Statements
- Python3 First Step
- Python3 Comprehensions
- Python3 Iterator and Generator
- Python3 with
- Python3 Function
- Python3 lambda (Anonymous Function)
- Python3 Decorator
- Python3 Data Structure
- Python3 Module
- Python __name__
- Python3 Input and Output
- Python3 File
- Python3 OS
- Python3 Errors and Exceptions
- Python3 Object-Oriented
- Python3 Namespace/Scope
- Python Virtual Environment Creation
- Python Type Hints
- Python3 Standard Library Overview
- Python3 Examples
- Python Quiz
Python3 Advanced Tutorial
- Python3 Regular Expressions
- Python3 CGI Programming
- Python MySQL - mysql-connector Driver
- Python3 MySQL Database Connection - PyMySQL Driver
- Python3 Network Programming
- Python3 SMTP Send Email
- Python3 Multithreading
- Python3 XML Parsing
- Python3 JSON Data Parsing
- Python3 Date and Time
- Python3 Built-in Functions
- Python3 MongoDB
- Python3 urllib
- Python uWSGI Installation and Configuration
- Python3 pip
- Python3 operator Module
- Python math Module
- Python requests Module
- Python random Module
- Python OpenAI
- Python Useful Resources
- Python AI Drawing
- Python statistics Module
- Python hashlib Module
- Python Quantitative
- Python pyecharts Module
- Python selenium Library
Python property() Function
The property() function is used to return the property attribute.
Grammar
property(fget=None, fset=None, fdel=None, doc=None)
Parameters
- fget -- Get attribute function
- fset -- Set attribute function
- fdel -- Delete attribute function
- doc -- Attribute description information
Return Value
Returns the property attribute.
Example
Using the property() function:
class C(object):
def __init__(self):
self._x = None
def getx(self):
return self._x
def setx(self, value):
self._x = value
def delx(self):
del self._x
x = property(getx, setx, delx, "I'm the 'x' property.")
c = C()
c.x = 'XMAN'
print(c.x)
del c.x
Output:
XMAN
If the c.x is not defined, the following example shows how the property attribute works:
class Parrot:
def __init__(self):
self._voltage = 100000
@property
def voltage(self):
"""Get the current voltage."""
return self._voltage
@voltage.setter
def voltage(self, new_value):
self._voltage = new_value
@voltage.deleter
def voltage(self):
self._voltage = 0
p = Parrot()
print(p.voltage)
p.voltage = 220
print(p.voltage)
del p.voltage
Output:
100000
220
YouTip