# -*- coding: utf-8 -*-
"""
Created on Fri May 10 23:04:35 2019
@author: User
"""
class Human(object):
'''
python3采用新式类
'''
phylum = 'Chordata'
order = 'Primates'
family = 'Human Being'
#使用类
ZhangSan = Human()
ZhangSan.family = 'Mankind'
print(ZhangSan.family)
LiSi = Human()
#ZhangSan.family = 'Mankind'
print(LiSi.family)
print('\n1-------------------\n')
Human.family = 'Homo'
print('ZhangSan.family: %s' %ZhangSan.family)
print('LiSi.family: %s' %LiSi.family)
WangWu = Human()
print('WangWu.family: %s' %WangWu.family)
ZhangSan.kingdom = 'Animalia' #为实例增加属性
print('ZhangSan.kingdom: %s' %ZhangSan.kingdom)
print('\n2-------------------\n')
#类的属性成员也可以直接增加
Human.kingdom = 'Animalia'
print('LiSi.kingdom: %s' %LiSi.kingdom)
运行:
Mankind
Human Being
1-------------------
ZhangSan.family: Mankind
LiSi.family: Homo
WangWu.family: Homo
ZhangSan.kingdom: Animalia
2-------------------
LiSi.kingdom: Animalia