python學習筆記之021.py

版權聲明:本文爲博主原創文章,未經博主允許不得轉載。 https://blog.csdn.net/zhendeaini18/article/details/77075444
#!/usr/bin/env python
# coding=utf-8
# Created Time:    2017-08-10 12:46:18
# Modified Time:   2017-08-10 13:11:33


# Filename: using_list.py


# This is my shopping list
shoplist = ['apple','mango','carrot','banana']


print 'I have', len(shoplist),'items to purchase.'


for item in shoplist:
    print item,


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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章