列表的增删查改

01 查

列表的查询与字符串的切边几乎一样,切片去查或者循环去查

如:

l1 = ['das', 'dfsdf',[1,23,],'asda']
li = l1[0]
print(li)
l2 = l1[0:3]
print(l2)
View Code

02 增

1 append 增加到最后

l1 = ['das', 'dfsdf',[1,23,],'asda']
l1.append('sfdg')
l1.append(324314)
print(l1)
View Code
l1 = ['das', 'dfsdf',[1,23,],'asda']

while 1:
    username = input('>>>')
    if username.upper().strip() == 'Q':
        break
    else:
        l1.append(username)
print(l1)
View Code

 

02 insert 选择插入

03 extend 迭代添加

l1 = ['das', 'dfsdf',[1,23,],'asda']
l1.extend("udhsfi")
l1.extend([1,2,3,4,5,6])
print(l1)
View Code

 

posted @ 2019-07-19 22:34  套你大象  阅读(92)  评论(0编辑  收藏  举报