python list

(1)properties:implemented by array
(2)common methods
lst=['d', 'd', 'g', 'n', 'o', 'y', 'y']
append(element)
sort()
reverse()
count() #lst.count('d') >>>2
index() #lst.index('d')  return the index-order of 'd' founded for the first time
expand(seq) 
pop() #lst.pop([INDEX]) remove the INDEX element(default last), and return the element
insert() #lst.insert(INDEX, OBJECT)
(3)list slicing
# lst
# Note: left close and right open:[2,6)
lst1 = lst[2:6:3] 
# get the last two elements
lst1 = lst[-2:]
(4)create list
list(range(10))
list(range(3,10))
list(range(2,10,2))
(5)create list by expr
lst = [x*x for x in range(10)]
(6)insert element
mode 1:list.insert(Index, Object)
mode 2:lst[0:0] = ['a','b','c'] ##insert a new element at the list top
(7)update element
lst[0:2] = ['a','b']

 

posted on 2016-04-18 21:30  qmzp  阅读(219)  评论(0)    收藏  举报

导航