keep码
度过大难,将有大成。 继续努力,终成大器。

以下是列表的一些知识点

name = ['关羽','张飞','刘备','曹操','诸葛亮','吕布',['吕布','吕布',],'吕布','吕布','吕布','吕布']
for i in name:
print(i)
print(name[0:-1:2])
print(name[:])

import copy
person = ['name',['a',100]]

p1=copy.copy(person)
p2=person[:]
p3=list(person)
print(p1)
print(p2)
print(p3)

p1=person[:]
p2=person[:]

p1[0]='keep'
p2[0]='隔壁老王'
p1[1][1]=20
print(p1)
print(p2)




print(name)
print(name[3])
print(name[3],name[0])
print(name[1:4])
print(name[0:4])#切片
print(name[0:-1])#顾前不顾后
print(name[-1])#取最后一个
print(name[-2:])#取倒数第二到最后
name.append('夏侯惇')#追加
name.insert(3,'赵子龙')#插入
print(name)
#name[3] = '司马懿'#更换


#delete
name.remove('刘备')
#del name[2] = name.pop(2)
print(name)
print(name.index('张飞'))
print( name[name.index('张飞')] )
print(name.count('吕布'))#计数
name.reverse()#反转
name.sort()#排序
name1 = ['a,b,c,d,f,g,h']
name.extend(name1)#拼加
print(name)
posted on 2019-02-20 17:20  keep码  阅读(212)  评论(0编辑  收藏  举报