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