class Student1: school = 'xiwangzhongxue' def __init__(self,name,age): self.name = name self.age = age def choice(self): print(f'{self.name}选课...') def study(self): print('学习....')
class Student1: school = 'xiwangzhongxue' def __init__(self,name,age): self.name = name self.age = age def choice(self): print(f'{self.name}选课...') def study(self): print('学习....') stu1 = Student('小明', 18) stu2 = Student('小红', 17) print(stu1.name) print(stu1.school)
小明python
xiwangzhongxue函数
print(Student.choice(123))
'int' object has no attribute 'name'学习
class Student1: school = 'xiwangzhongxue' def __init__(self, name,age): self.name = name self.age = age def choice(self): print(f'{self.name}选课...') def study(self): print('学习....') stu1 = Student1('小明',18) stu1.choice() stu2 = Student1('小红',20) stu2.choice()
小明选课...
小红选课...code