python中的类
class Student:
native_pace = '成都'
def __init__(self,name,age):
self.name= name
self.age = age
def play(self):
print(self.name +'在玩老头环')
@staticmethod
def method():
print('一个静态方法')
@classmethod
def cm(cls):
print('一个类方法')
def drink():
print('鸡汤来喽,喝,怎么不喝啊')
创建Student类的对象
stu1=Student('鳄小霸',20)
stu2=Student('蟑大郎',18)
stu1.play()
Student.play(stu1)
print(stu1.name)
print(stu1.age)
print(stu1.native_pace)
stu1.native_pace='重庆'
print(stu1.native_pace)
Student.cm()
Student.method()
stu1.gender='雄性'
print(stu1.name,stu1.age,stu1.gender)
drink()
stu1.drink=drink
stu1.drink()