Python定义一个学生类包含姓名年龄
class Student: def init(self, name, age): self.name = name self.age = age
Example usage
student1 = Student("John", 20) student2 = Student("Jane", 22)
print(student1.name) # Output: John print(student1.age) # Output: 20
print(student2.name) # Output: Jane print(student2.age) # Output: 22
原文地址: http://www.cveoy.top/t/topic/iU7z 著作权归作者所有。请勿转载和采集!