Python--实例变量

class Person(object):
country = 'China' # 类变量

def __init__(self, name, age, sex):
self.name = name # 实例变量,必须实例化才能用,也叫成员变量
self.age = age
self.sex = sex

def say_my_country(self):
print(self.country)


# dsx = Person('大师兄', 23, '男')
# print(dsx.name)
# print(dsx.age)
# print(dsx.sex)
# print(dsx.country)
# ds = Person('原宝清', 28, '男')
print(Person.country)
posted @ 2018-02-09 16:20  王思磊  阅读(114)  评论(0编辑  收藏  举报