python list pop能移除none值么
答案:1 悬赏:10 手机版
解决时间 2021-03-19 22:07
- 提问者网友:锁深秋
- 2021-03-19 14:24
python list pop能移除none值么
最佳答案
- 五星知识达人网友:山有枢
- 2021-03-19 14:31
在交互模式试一下就知道了:
Python 3.5.3 (default, Jan 19 2017, 14:11:04)
[GCC 6.3.0 20170118] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> a = [1, 2, None]
>>> a.pop()
>>> a
[1, 2]
>>> a.append(None)
>>> a.pop(None)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object cannot be interpreted as an integer
>>> a.pop(-1)
>>> a
[1, 2]
Python 3.5.3 (default, Jan 19 2017, 14:11:04)
[GCC 6.3.0 20170118] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> a = [1, 2, None]
>>> a.pop()
>>> a
[1, 2]
>>> a.append(None)
>>> a.pop(None)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object cannot be interpreted as an integer
>>> a.pop(-1)
>>> a
[1, 2]
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯