首页 > 编程语言 > 详细

Python_week5_lists

时间:2014-10-24 01:39:52      阅读:176      评论:0      收藏:0      [点我收藏+]

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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!