# -*- coding: utf-8 -*-
"""
Created on Sun May 12 22:35:34 2019
@author: User
"""
class Human(object):
domain = 'eukarya'
def __init__(self, kingdom='Animalia',phylum='Chordata',
order='Primates',family='Human Being'):
self.kingdom = kingdom
self.phylum=phylum
self.order = order
self.family = family
def typewrite(self):
print('This is %s typing words!' %self.family)
def add(self, n1, n2):
n = n1 + n2
print(str(n1) + '+' + str(n2) + '+' + str(n))
print('You see! %s can calculate!' %self.family)
@classmethod
def showclassattributeinfo(cls):
print(cls.__name__) #__name__属性,其值为类名
print(dir(cls)) #使用dir列示本类的所有方法
@staticmethod
def showclassattributeinfo():
print(Human.__dict__)
ZhangSan = Human()
print(ZhangSan.showclassattributeinfo())
print(Human.showclassattributeinfo())
运行:
{'__module__': '__main__', 'domain': 'eukarya', '__init__': <function Human.__init__ at 0x000000C7D0E4D0D0>, 'typewrite': <function Human.typewrite at 0x000000C7D0F047B8>, 'add': <function Human.add at 0x000000C7D0F04D08>, 'showclassattributeinfo': <staticmethod object at 0x000000C7D0F1E0B8>, '__dict__': <attribute '__dict__' of 'Human' objects>, '__weakref__': <attribute '__weakref__' of 'Human' objects>, '__doc__': None}
None
{'__module__': '__main__', 'domain': 'eukarya', '__init__': <function Human.__init__ at 0x000000C7D0E4D0D0>, 'typewrite': <function Human.typewrite at 0x000000C7D0F047B8>, 'add': <function Human.add at 0x000000C7D0F04D08>, 'showclassattributeinfo': <staticmethod object at 0x000000C7D0F1E0B8>, '__dict__': <attribute '__dict__' of 'Human' objects>, '__weakref__': <attribute '__weakref__' of 'Human' objects>, '__doc__': None}
None