python笔记:2.1.2.2类方法

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

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值