class Student: company = 'LOL' @classmethod def say_company(cls): print(cls.company) Student.say_company()
与类方法界限不清晰,可以访问类,只是不通过CLS
class Student: company = 'LOL' @staticmethod def add(a,b): print(Student.company) print("{0}+{1}={2}".format(a,b,a+b)) Student.add(1,2)
两种方法多不能访问实例变量。