python----将对象放入列表中

类 作为数据模型使用

class Student(object):
    # 初始化中给对象属性赋值
    def __init__(self,name , age, phone):
        self.name = name
        self.age = age
        self.phone = phone

s1 = Student('张三', 22, 110)
s2 = Student('李四', 21, 120)
s3 = Student('王五', 21, 120)

student_list = [s1,s2,s3]

s1 = student_list[0]
s1.name = '张三丰'
print(s1.name)

你可能感兴趣的:(计算机基础,刷题)