标签:stu1 name self 实例 Student print
面向对象
class定义类
类和实例
class Student:
# 类属性
province = '天津'
def init(self,name):
# 实例属性
self.name = name
# 实例方法
def say(self):
# 类方法
@classmethod
def hello(cls):
print(cls,'hello world')
# 静态方法
@staticmethod
def world():
print('你好')
# 类的实例化
stu1 = Student('张三')
stu2 = Student('李四')
print(stu1.name,stu1.province)
print(stu2.name,stu2.province)
print(Student.province)
stu1.say()#调用实例方法
stu2.say()
Student.hello()#类方法
Student.world()#静态方法
stu1.hello()
stu1.world()
标签:stu1,
name,
self,
实例,
Student,
print
From: https://www.cnblogs.com/striveforward/p/18241217