shoplist = ['apple', 'mango', 'carrot', 'banana'] #定义一个列表

print 'I have', len(shoplist),'items to purchase' #计算列表长度

print 'These items are:',  #遍历列表
for item in shoplist:
    print item,
    
print '\nI also to buy rice'
shoplist.append('rice') #列表当中添加item
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

 

相关文章:

  • 2021-09-01
  • 2021-12-28
  • 2021-08-16
  • 2022-02-18
  • 2021-10-23
  • 2021-04-26
猜你喜欢
  • 2021-05-28
  • 2022-01-09
  • 2021-12-01
  • 2022-12-23
  • 2019-03-02
  • 2021-05-25
  • 2022-02-26
相关资源
相似解决方案