Python中类的相关知识
class Student:
address='辽宁'#类属性
def __init__(self,name,age):#初始化方法
self.name=name
self.age=age
#------------------------------实例方法
def eat(self):
print(self.name+"爱吃鱼")
#-------------------------------静态方法
@staticmethod
def method():
print('这是静态方法,static method')
#--------------------------------类方法
@classmethod
def method1(cls):
print("这是类方法")
#---------------------------------创建对象
stu=Student('张三',14)
stu.eat()#调用实例方法
Student.eat(stu)#调用实例方法
Student.method1()#调用类方法
Student.method()#调用静态方法
stu.method1()#调用类方法
stu.method()#调用静态方法
#----------------------------------动态绑定
def sing():
print("动态绑定的函数")
stu.sing=sing
stu.sing()