比如, 输入英文代码:
# This is my shopping list
shoplist = ['apple', 'mango', 'carrot', 'banana']
print('I have', len(shoplist), 'items to purchase.')
print('These items are:', end=' ')
for item in shoplist:
print(item, end=' ')
print('\nI also have to buy rice.')
shoplist.append('rice')
print('My shopping list is now', shoplist)
print('I will sort my list now')
shoplist.sort()
print('Sorted shopping list is', shoplist)
print('The first item I will buy is', shoplist[0])
olditem = shoplist[0]
del shoplist[0]
print('I bought the', olditem)
print('My shopping list is now', shoplist)
返回中文对应代码:
# 这是我的购物单
购物单 = ['苹果', '芒果', '胡萝卜', '香蕉']
打印('我有', 长度(购物单), '要购买的产品.')
打印('这些物品是:', 结尾=' ')
对于 物品 在 购物单:
打印(物品, 结尾=' ')
打印('\n 我还得买大米.')
购物单.添加('米')
打印('我的购物单现在在', 购物单)
打印('我现在就整理我的清单')
购物单.排序()
打印('排序的购物清单是', 购物单)
打印('我要买的第一件东西是', 购物单[0])
第一项 = 购物单[0]
删除 购物单[0]
打印('我买过', 第一项)
打印('我的购物单现在在', 购物单)
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.