python小记~列表,字符串

Step one:将赋值号(=)左边指定的内容删除

Step two:将包含在赋值号(=)右边的可迭代对象中的片段插入左边被删除的位置

其实它是分上面两个步骤实现的

>>> heroes = ['zhizhuxia','meilide','mieba','putao','chengzi']
>>> heroes[4]='baby'
>>> heroes
['zhizhuxia', 'meilide', 'mieba', 'putao', 'baby']
>>> heroes[3:] = ['boke','weibo','tengxun','jimei']
>>> heroes
['zhizhuxia', 'meilide', 'mieba', 'boke', 'weibo', 'tengxun', 'jimei']

1.排序,顺序排序sort()

>>> nums = [2,5,1,3,4,6,3]
>>> nums.sort()
>>> nums
[1, 2, 3, 3, 4, 5, 6]

2.排序,倒序排序reverse()
nums = [1, 2, 3, 3, 4, 5, 6]
>>> nums.reverse()
>>> nums
[6, 5, 4, 3, 3, 2, 1]

或者是nums.sort(reverse = True)

3.查找索引值

>>> nums = [4,2,5,3,6,8,0,4,3]
>>> nums.index(3)
3

>>> nums.index(3,0,8)
3

第一个参数是查找的参数,第二个和第三个参数是索引值的下标

4.copy(),浅拷贝

>>> nums = [4,2,5,3,6,8,0,4,3]

>>> nums_copy1 = nums.copy()
>>> nums_copy1
[4, 2, 5, 3, 6, 8, 0, 4, 3]
>>> nums_copy2 = nums[:]
>>> nums_copy2
[4, 2, 5, 3, 6, 8, 0, 4, 3]
>>> 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值