# -*- coding: utf-8 -*-
"""
Created on Sun May 12 20:21:22 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 showclassmethodinfo(cls):
print(cls.__name__) #__name__属性,其值为类名
print(dir(cls)) #使用dir列示本类的所有方法
ZhangSan = Human()
print(ZhangSan.showclassmethodinfo())
print(Human.showclassmethodinfo())
运行:
Human
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'add', 'domain', 'showclassmethodinfo', 'typewrite']
None
Human
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'add', 'domain', 'showclassmethodinfo', 'typewrite']
None