P68#定义元组student_info_技术宅的夏天
P68
# 定义元组
student_info = ('周杰轮', 11, ['football', 'music'])
# 查询年龄所在下标位置
age_index = student_info.index(11)
print("年龄所在下标位置为:", age_index)
# 查询学生姓名
name = student_info[0]
print("学生姓名为:", name)
# 删除爱好中的football
hobbies = list(student_info[2]) # 将元组中的列表转换为可变列表
hobbies.remove('football')
student_info = (student_info[0], student_info[1], hobbies) # 重新构建元组
print("删除football后的元组为:", student_info)
# 增加爱好:coding到爱好list内
hobbies.append('coding')
student_info = (student_info[0], student_info[1], hobbies) # 重新构建元组
print("增加coding后的元组为:", student_info)
黑马程序员python教程,8天python从入门到精通,学python看这套就够了