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')

元组不能修改

posted @ 2017-06-12 20:52  ~沐风  阅读(237)  评论(0编辑  收藏  举报