python笔记:list--pop与remove的区别
2024-08-28 07:09:53
正常情况下:
# coding=utf-8 fruit = ['apple', 'pear', 'banana' ]
#指定索引删除
fruit.pop(0)
#符合元素删除,具体数值
fruit.remove('pear')
print(fruit) 运行结果:
['banana']
反例:
pop用指定元素:
# coding=utf-8 fruit = ['apple', 'pear', 'banana' ]
fruit.pop('apple') 运行结果:
Traceback (most recent call last):
File "...XXX.py", line 5, in <module>
fruit.pop('apple')
TypeError: 'str' object cannot be interpreted as an integer
remove用索引:
# coding=utf-8 fruit = ['apple', 'pear', 'banana' ]
fruit.remove(0)
print(fruit) 运行结果:
Traceback (most recent call last):
File "...XXX.py", line 4, in <module>
fruit.remove(0)
ValueError: list.remove(x): x not in list
最新文章
- 升级python2.7至python3
- B树详解
- PL/0编译器(java version) &ndash; Scanner.java
- git: No refs in common and none specified; doing no
- Linux安全运维日志排查几个 tips
- java多线程模拟停车系统
- poj 3252 Round Numbers 【推导&#183;排列组合】
- [转贴] C++内存管理检测工具 Valgrind
- iOS- 解决iOS10 App启动时放大铺满App Icon的问题
- 《英文写作指南 The elements of style》【PDF】下载
- IDEA jsp模板
- linux socket编程之TCP与UDP
- [Swift]LeetCode159.具有最多两个不同字符的最长子串 $ Longest Substring with At Most Two Distinct Characters
- 使用ML.NET实现白葡萄酒品质预测
- 算法——001BitMap(位图)算法
- hive命令的三种执行方式
- 利用OCR识别扫描的jpg、tif文件的文字
- python的__getitem__
- Hbase 维护
- ASP.NET 构建高性能网站 第1篇
热门文章
- 专业视频图片水印清除工具丨HitPaw Watermark Remover 2.1.3
- 解决Google翻译不能用的问题
- 基2和基4FFT
- MaaS模型即服务
- window操作
- uniapp 配置钉钉小程序package.json文件
- 滚动 Scroller OverScroller
- sed 命令添加字符串
- C#和.NET Framework 简介
- python torch 解决OSError: [WinError 126] 找不到指定的模块。 Error loading ";D:\Anaconda3\lib\site-packages\torch\lib\asmjit.dll"; or one of its dependencies.(安装完torch模块后出现找不到指定模块的问题)