day07_03 类方法与类变量

__author__ = "Alex Li"

import os
# os.system()
# os.mkdir()

class Dog(object):
    name = "huazai"
    def __init__(self,name):
        self.name = name

    #只能访问类变量,不能访问实例变量,强制使用类变量
    @classmethod
    def eat(self):
        print("%s is eating %s" %(self.name,'dd'))

    def talk(self):
        print("%s is talking"% self.name)


d = Dog("ChenRonghua")
d.eat()
posted @ 2021-06-06 12:05  flytoyou  阅读(16)  评论(0编辑  收藏  举报