# -*- coding: utf-8 -*-"" "created on sun nov 13 23:19:03 2016@author: toby "" "#知识点: @property the method into a feature with the adorner class province: memo = ' one of china\ ' s 23 provinces ' #静态字段 def __init__ (self,name,capital,leadership): self. name = name #动态字段 self. capital = capital #动态字段 self. leadership = leadership #动态字段 def sports (self): #定义一个动态方法, class cannot access dynamic methods print self. name + ' the sports meeting ' #把方法变成一个特性 @property #自带的装饰器   &NBSp; 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
This article is from the "Fa&it-Q Group: 223843163" blog, please be sure to keep this source http://freshair.blog.51cto.com/8272891/1874165
Python's decorator @property, turning the method into a feature