python list 操作 增删查

List查询数组里面的元素直接   数组名称.[数组序号]就可以了

例如数组b, b[2]
<span style="font-size:18px;"><strong>增加元素有3种方式</strong></span>
1.append() 增加在最后面
例如
<pre name="code" class="python">b.append('world')

2.insert()可以进行选择插入到第几个
例如:
>>> b.insert(0,'xiao')
3.extend() 增加多个元素
例如
>>> b.extend(['by','pragram'])
删除元素有3种方式

remove() 直接移除list中的字符串
例如
b.remove('xiao')

del 直接移除list序号的字符串
例如
del b[2]

pop()
例如

b.pop(2)
默认是最后一个
>>> b=['change','the']
>>> b.append('world')
>>> b['change', 'the', 'world']
>>> b.extend(['by','pragram'])
>>> b['change', 'the', 'world', 'by', 'pragram']
>>> b.insert(0,'xiao')
>>> b['xiao', 'change', 'the', 'world', 'by', 'pragram']
>>> b[2]'the'
>>> b.remove('xiao')
>>> b['change', 'the', 'world', 'by', 'pragram']
>>> del b(1)SyntaxError: can't delete function call
>>> del b[1]
>>> b['change', 'world', 'by', 'pragram']
>>> a=b;
>>> b.pop()'pragram'
>>> b['change', 'world', 'by']
>>> name=b.pop()
>>> name'by'
>>> name=b.pop(1)
>>> name'world'
>>> b['change']
>>>




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值