# @File : 3.2修改、添加和删除元素.py
# @Software: PyCharm
guests=['Black','Pink','Orange']
message1="Now I invite "+ guests[0] +"、"+guests[1]+" and "+guests[2]+" to my birthday party on July 7th."
print(message1)
print("For some reason,Blak can't join.")
del guests[0]
guests.insert(0,"Red")
message3="Now I invite "+ guests[0] +"、"+guests[1]+" and "+guests[2]+" to my birthday party on July 7th."
print(message3)
print("By chance,I found a bigger dining-table.")
guests2=['Haha','Xixi','Sea']
guests.insert(0,guests2[0])
guests.insert(2,guests2[1])
guests.append(guests2[2])
message5="Now I invite "+ guests[0] +"、"+guests[1]+"、"+guests[2]+"、"+guests[-3]+"、"+guests[-2]+" and "+guests[-1]+" to my birthday party on July 7th."
print(message5)
print("Unfortunately, I just received the news that the newly purchased large dining tables could not be delivered on time.")
print("So I can only invite two guests to have a birthday dinner together.")
#为了自己看的更清楚,但正式场合不应出现列表
print(guests)
#特别注意:在列表中删除一个元素后,其他元素的位置也会受到影响,所以要注意pop()后面的索引号
first_not_guest=guests.pop(1)
print("I'm terribly sorry,"+first_not_guest+", I can't invite you to my birthday party.")
#如上提醒,后面的索引号都是2
second_not_guest=guests.pop(2)
print("I'm terribly sorry,"+second_not_guest+", I can't invite you to my birthday party.")
third_not_guest=guests.pop(2)
forth_not_guest=guests.pop(2)
print("I'm terribly sorry,"+third_not_guest+" and "+forth_not_guest+", I can't invite you to my birthday party.")
print("I'm terribly sorry,"+third_not_guest+" and "+forth_not_guest+", I can't invite you to my birthday party.")
print("Dear "+guests[0]+" and "+guests[1]+",you are still among the invitees. I hope you will come to my birthday party on time.")
#确定列表长度
print("Finally, I invited "+str(len(guests))+ " people to my birthday party.")
del guests[0]
#再删除第一个元素后,列表中就只剩一个元素,因此下面的索引号仍然是0
del guests[0]
print(guests)