python笔记:2.1.2.3静态方法

# -*- 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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值