This article mainly for you in detail the python with the adorner @property method into a feature example, interested in the small partners can refer to
#-*-Coding:utf-8-*-"" "Created on Sun Nov 23:19:03 @author: Toby" "" #知识点: Use the adorner @property to turn the method into an attribute class province: Memo = ' One of China\ ' s provinces ' #静态字段 def __init__ (self,name,capital,leadership): Self . Name = name #动态字段 self . Capital = Capital #动态字段 self . Leadership = Leadership #动态字段 def Sports (self): #定义一个动态方法, the class cannot access the dynamic method print self. Name + ' The Sports meeting ' #把方法变成一个特性 @property #自带的装饰器 def Bar (self): print self. Name return ' somthing ' #也是可以有一个返回值的 #实例化两个对象, the object names are: HB, SDHB = Province (' Hebei ', ' Shjiazhuang ', ' Liyang ') SD = Province (' Shandong ', ' Jinan ', ' Angshenghui ') #通过对象访问这个属性, the Access form of the method becomes the Access form of the Access field print HB. Bar