Python入门系列教程(三)列表和元组
增
1.insert
A = ['1','2','3','4','5','6'] A.insert(0,0) print A
2.append
A = ['1','2','3','4','5','6'] A.append(7) print A
3.extend
A = ['1','2','3','4','5','6'] B = ['a','b','c'] A.extend(B) print A
删
1.pop
A = ['1','2','3','4','5','6'] A.pop() print A
2.remove
A = ['1','2','3','4','5','6'] A.remove('1') print A
3.del
A = ['1','2','3','4','5','6'] del A[0] print A
改
A = ['1','2','3','4','5','6'] A[0]=0 print A
查
in
A = ['1','2','3','4','5','6'] for temp in A: print temp
A = ['1','2','3','4','5','6'] if '5' in A: print '确实在'
not in
A = ['1','2','3','4','5','6'] if '7' not in A: print '确实不在'
index:返回查找元素的下标
A = ['1','2','3','4','5','6'] print A.index('1')
count:返回查找元素的个数
A = ['1','2','3','4','5','6'] print A.count('1')
列表嵌套
A = ['1','2','3','4','5','6',['1','2','3'],['4','5','6']] for item in A: print item
元组
A = ('1','2','3','4','5','6')
元组不能修改