class Student:
pass
native_pace='吉林'
def __init__(self,name,age):
self.name=name
self.age=age
def eat(self):
print('学生在吃饭!')
@staticmethod
def method():
print('使用了staticmethod进行修饰,所以是静态方法!')
@classmethod
def me(cls):
print('使用了classmethod进行修饰,所以是类方法!')
def drink():
print('学生在喝水!')
print(id(Student))
print(type(Student))
print(Student)
print('----------------------')
stu1=Student('张三',20)
print(id(stu1))
print(type(stu1))
print(stu1)
stu1.eat()
print(stu1.name)
print(stu1.age)
print('------------------------')
Student.eat(stu1)
print(Student.native_pace)
stu2=Student('李四',30)
print(stu1.native_pace)
print(stu2.native_pace)
Student.native_pace='天津'
print(stu1.native_pace)
print(stu2.native_pace)
print('----------------------------')
Student.me()
Student.method()
print('------------------')
class Student1:
def __init__(self,name,age):
self.name=name
self.age=age
def eat(self):
print(self.name+'在吃饭')
stu3=Student1('张三',20)
stu4=Student1('李四',30)
print('------为stu3动态绑定性别属性-------------')
stu3.gender='女'
print(stu3.gender)
print('-------------------------')
stu3.eat()
stu4.eat()
def show():
print('定义在类之外,称为函数')
stu3.show=show
stu3.show()
