Python面向对象之静态方法
@staticmethod 不能访问类变量、也不能访问实例变量
class Student(object):
role = "Stu"
def __init__(self,name):
self.name = name
@staticmethod
def fly(self):
print(self.name,"is flying")
@staticmethod
def walk():
print("student walking...")
s = Student("jack")
s.fly(s)
s.walk()
结果:
jack is flying
student walking...