当前第2页 返回上一页
4.如何截取list中的某一段
1 2 | print (fruit[: 2]) #从list的首元素开始截取,截取到位置 '3' ,但不包括第3个元素
[ 'apple' , 'banana' ]
|
5. 如何更改list中连续的元素
1 2 3 | fruits[:2] = [ 'a' , 'b' ]
print (fruits)
[ 'a' , 'b' , 'tomato' , 'grapes' , 'pineapple' , 'watermelon' , 'eggplant' ]
|
6.如何删除list中某段元素,或者全部list
1 2 3 4 5 | fruits[:2] = [] #删除前两个元素
print (fruits)
[ 'tomato' , 'grapes' , 'pineapple' , 'watermelon' , 'eggplant' ]
fruits[:] = [] #删除全部list元素
[]
|
相关推荐:
python创建列表和向列表添加元素的实现方法_python
以上就是Python 创建空的list,以及append用法讲解的详细内容,更多文章请关注木庄网络博客!!
返回前面的内容
相关阅读 >>
Python全栈是什么意思
Python计算平均值
Python怎么创建django
Python中关于数字的详解
Python基础教程适合初学者吗
Python怎么调用youget
Python画图的两种方法
Python之property()装饰器的使用详解
Python比java慢多少
哪些网站全用Python
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » Python 创建空的list,以及append用法讲解