list 访问for
list = [a,b,c] for n in list: print n #a #b #c sum()函数 list = [1,3,5] sum(list) #9
append()函数
list = [1, 2, 4] list.append(6) print list #[1, 2, 4, 6]
list的三种删除方法
n = [1,3,5]
pop() n.pop(index) n.pop(1) #returns 3 print n # [1,5] remove() n.remove(item) n.remove(1) print n #[3,5] del del(n[index]) #doesnot return anything del(n[1]) print n #[1, 5] range用法 range(6) # => [0,1,2,3,4,5]range(1,6) # => [1,2,3,4,5]range(1,6,3) # => [1,4] The range function has three different versions: range(stop) range(start, stop) range(start, stop, step) list for 的方法:
Method 1 - for item in list
:
for item in list: print item
Method 2 - iterate through indexes:
for i in range(len(list)): print list[i] letters = [‘a‘, ‘b‘, ‘c‘, ‘d‘] print "---".join(letters) # a---b---c---d
本文出自 “杨柳岸” 博客,请务必保留此出处http://jackzones.blog.51cto.com/5001676/1723313
1215--list,dictory的访问方法,list的三种删除方法,range用法,list的
原文:http://jackzones.blog.51cto.com/5001676/1723313