作业二

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)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值