3.12python作业

这篇博客展示了Python的基础操作,包括列表元素的访问、字符串拼接、列表的修改以及排序方法。通过示例代码,作者演示了如何打印列表中的特定元素,如何邀请名单上的人物参加晚宴,并在名单变动时更新邀请。此外,还介绍了如何对列表进行排序,包括升序、降序排列以及使用sort()函数改变列表顺序的操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

# 3-1
names = ['James', 'Trump', 'Mike', 'John']
print(names[0])
print(names[1])
print(names[2])
print(names[-1])


# 3-4
names = ['James', 'Trump', 'John']
print(names[0] + ', I invite you to my dinner. Would you come?')
print(names[1] + ', I invite you to my dinner. Would you come?')
print(names[2] + ', I invite you to my dinner. Would you come?')


# 3-5
print("I am sorry to hear that John can't come to my dinner. So I invite another one.")
names[2] = 'Mike'
print(names[0] + ', I invite you to my dinner. Would you come?')
print(names[1] + ', I invite you to my dinner. Would you come?')
print(names[2] + ', I invite you to my dinner. Would you come?')

# 3-8
places = ['America', 'Hong Kong', 'Britain', 'Japan', 'Canada']
print(places)
print(sorted(places))
print(places)
print(sorted(places,reverse =True))
print(places)
places.reverse()
print(places)
places.reverse()
print(places)
places.sort()
print(places)
places.sort(reverse=True)
print(places)


# 3-11
list = [1,2,3,4]
print(list[4])

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值