列表的增删查改

01 查

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

如:

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

02 增

1 append 增加到最后

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

l1 = [‘das‘, ‘dfsdf‘,[1,23,],‘asda‘]

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

02 insert 选择插入

03 extend 迭代添加

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

原文地址:https://www.cnblogs.com/zly9527/p/11216070.html

时间: 2024-10-08 09:36:46

列表的增删查改的相关文章

python中列表的增删查改

本文将学习python中对列表中的元素进行增删查改操作以l为例:l=['hello','tomorrow','!']1.增加:(1)在列表末尾增添元素:列表名.append('element') l.append('hello') print(l) 输出:(2)在列表任意位置插入元素:列表名.insert(索引,'element')l.insert(1,"luu's")print(l)输出: 2.删除(1)del 列表名[序号] del l[1] print(l) (2)列表名.pop

列表的增删查改 续

删 pop按索引去删 l1 = ['das', 'dfsdf',[1,23,],'asda'] name = l1.pop(1)#返回被删除的值,按索引去删除 print(name,l1) 若不写删除元素索引,默认删除最后一个 remove 按元素值去删 l1 = ['das', 'dfsdf',[1,23,],'asda'] l1.remove('asda') print(l1) clear 清空  del 删除列表 l1 = ['das', 'dfsdf',[1,23,],'asda'] l

python中关于list列表的增删查改操作

python中list的操#python创建列表的时候,会以堆栈的形式存放数据,从右向左往堆栈中存放数据 movies=["The holy Grail","The life of brain","The meaning of life"] movies=[] #len()表示长度print(len(movies))#python append在列表的末尾添加一个元素movies.append("Gillain")#pytho

2017-12-19python全栈9期第四天第二节之列表的增删查改之删除的pop和del和remove和clear

#!/user/bin/python# -*- coding:utf-8 -*-li = ['zs','ls','ww','zl']# name = li.pop(1) #按索引位置删除有返回值# name1 = li.pop()#默认删除最后一个有返回值# print(name,name1,li)# li.remove('ls') #按指定位置删除# print(li)li.clear() #清空print(li)# del li# print(li) 原文地址:https://www.cnb

2017-12-19python全栈9期第四天第二节之列表的增删查改之按切片删除

#!/user/bin/python# -*- coding:utf-8 -*-li = ['zs','ls','ww','zl','xx']# del li[1:] #1到最后# print(li)del li[0:3] #顾头不顾尾print(li) 原文地址:https://www.cnblogs.com/zhang-da/p/10199282.html

2017-12-19python全栈9期第四天第二节之列表的增删查改之元祖是只读列表、可循环查询、可切片、儿子不能改、孙子可以改

#!/user/bin/python# -*- coding:utf-8 -*-tu = ('zs','ls','ww',[1,2,3,4,5,'zxcvb'],'zl')print(tu[3])print(tu[0:4])for i in tu: print(i)tu[3][5] = tu[3][5].upper()print(tu)tu[3].append('fdsfds')print(tu) 原文地址:https://www.cnblogs.com/zhang-da/p/10203243.

EF实现增删查改功能

In the previous tutorial you created an MVC application that stores and displays data using the Entity Framework and SQL Server LocalDB. In this tutorial you'll review and customize the CRUD (create, read, update, delete) code that the MVC scaffoldin

实现基本的增删查改功能

1. In the previous tutorial you created an MVC application that stores and displays data using the Entity Framework and SQL Server LocalDB. In this tutorial you'll review and customize the CRUD (create, read, update, delete) code that the MVC scaffol

一套手写ajax加一般处理程序的增删查改

倾述下感受:8天16次驳回.这个惨不忍睹. 好了不说了,说多了都是泪. 直接上代码 : 这个里面的字段我是用动软生成的,感觉自己手写哪些字段太浪费时间了,说多了都是泪 ajax.model层的代码: using System; namespace Ajax.Model { /// <summary> /// SM_Class:实体类(属性说明自动提取数据库字段的描述信息) /// </summary> [Serializable] public partial class SM_C