# -*- coding: utf-8 -*-
"""
Created on Sun Nov 13 23:19:03 2016
@author: toby
"""
#知识点:用装饰器@property,把方法变成一个特性
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): #定义一个动态方法,类不能访问动态方法
print self.Name + 'The sports meeting'
#把方法变成一个特性
@property #自带的装饰器
def Bar(self):
print self.Name
return 'somthing' #也是可以有一个返回值的
#实例化两个对象,对象名分别是:hb、sd
hb = Province('hebei','shjiazhuang','liyang')
sd = Province('shandong','jinan','angshenghui')
#通过对象访问这个属性,把方法的访问形式变成访问字段的访问形式
print hb.Bar
Copyright © 2019- tachun.com.cn 版权所有
违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务