3-4 :嘉宾名单——选择邀请共享晚餐的人
person=["GaoErJi","NiuDun","liuZi","God"] #创建人名列表
print(person[0].title()+", "+person[1]
.title()+", "+person[2]
.title()+" and "+person[3]
.title()+", could you take a dinner with me?")
3-5:
1、指出一名无法到场的嘉宾
print("The "+person[-1]+"can't spend time on taking dinner with us.")
2、修改名单并再发出邀请
del(person[-1])
person.append("huangHun")
print(person[0].title()+", "+person[1]
.title()
+", "+person[2]
.title()
+" and "+person[3]
.title()
+", could you take a dinner with me?")
3-9:打印出晚餐邀请了多少位嘉宾
print(len(person))
3-10:使用本章每个函数对列表进行一次操作
选择对person进行操作,首先peroson为四个元素的列表,包括
"GaoErJi","NiuDun","liuZi"和"huangHun"
person.append("123") #在末尾添加字符串"123"
person.insert(2,"345")#在位置2插入"345"
del(person[2]) #删除"345"
person.pop() #删除末尾的"123"
person.remove("haungHun")
person.sort()
person,sort(reverse=True)