码迷,mamicode.com
首页 > 编程语言 > 详细

Python_week5_lists

时间:2014-10-24 01:41:57      阅读:199      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   ar   for   strong   sp   

list

list.reverse()

list.sort()

list.index(obj):obj is the object to be find out; it returns index of the found object otherwise raise an exception indicating that value does not find.

aList = [123, ‘xyz‘, ‘zara‘, ‘abc‘];

print "Index for xyz : ", aList.index( ‘xyz‘ ) ; //return  1
print "Index for zara : ", aList.index( ‘zara‘ ) ;//return  2

list.append(x)

list.insert(i, x):insert x after list[i].

list.pop():the last item will be removed.

list.pop(3) :delete the list[3].the argument is index.so sometimes, you may use list.pop(list.index(obj))

list.remove(sth):delete the ‘sth‘.

list.extend(an_iter):add each item from the iterable an_iter onto the list.

Difference between extend and append:

bubuko.com,布布扣

 

 

iteration

warning: we can‘t modify a list while interating over it.

settle: create another list

Python_week5_lists

标签:style   blog   http   color   io   ar   for   strong   sp   

原文地址:http://www.cnblogs.com/beatrice7/p/4045336.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!