从列表中删除项目会导致列表变为 NoneType [英] Removing item from list causes the list to become NoneType
本文介绍了从列表中删除项目会导致列表变为 NoneType的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想有一个我忽略的简单解决方案.总比复杂的好,对吧?
I imagine there is a simple solution that I am overlooking. Better that than a complicated one, right?
简单地说:
var = ['p', 's', 'c', 'x', 'd'].remove('d')
导致 var
的类型为 None
.这是怎么回事?
causes var
to be of type None
. What is going on here?
推荐答案
remove
不返回任何内容.它就地修改现有列表.无需分配.
remove
doesn't return anything. It modifies the existing list in-place. No assignment needed.
替换
var = ['p', 's', 'c', 'x', 'd'].remove('d')
与
var = ['p', 's', 'c', 'x', 'd']
var.remove('d')
现在 var
的值为 ['p', 's', 'c', 'x']
.
这篇关于从列表中删除项目会导致列表变为 NoneType的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文