Python List(列表)使用示例
2013-05-15 09:23
537 查看
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
相关文章推荐
- Python面试题 之 Uniquify a list 不使用set去除一个列表中的重复项,并且保持原有的排列顺序
- python之列表(list)的使用方法介绍
- 使用python对列表(list)去重
- python函数max与min的高阶使用,list强转的本质,字典列表比值办法max的隐藏功能
- python列表(list)的使用技巧及高级操作
- python之列表(list)的使用方法介绍
- Python中list列表的一些进阶使用方法介绍
- python之列表(list)的使用方法介绍
- python之列表(list)的使用方法介绍
- python list使用示例 list中找连续的数字
- Python 列表list使用介绍
- python之列表(list)的使用方法介绍
- python分割列表(list)的方法示例
- python列表list使用实例
- Python列表和元组的定义与使用操作示例
- python之列表(list)的使用方法介绍
- Python3之列表list使用
- python之列表(list)的使用方法介绍
- 在Python中操作列表之List.append()方法的使用
- Python中list列表的一些进阶使用方法介绍