我不是python方面的专家,我希望一些专家能帮助我理解我在下面尝试的两种方法的输出差异
from nltk.corpus import stopwords
stop_words = stopwords.words('english')
stop_words.extend(['from', 'subject'])
from nltk.corpus import stopwords
stop_words = stopwords.words('english').extend(['from', 'subject'])
我认为第二种方法与第一种方法相同,但我错了。我无法理解这种行为改变背后的原因
TL;博士
list.extend()
扩展列表,但返回无。这是使用
list.extend()
的正确方法:让我们看看
stop_words
类型是什么:如果我们看一下https://docs.python.org/3/tutorial/datastructures.html
下面是CPython中list extend函数的实现:https://github.com/python/cpython/blob/master/Objects/listobject.c#L872
我们看到函数返回
Py_RETURN_NONE;
要在Python使用中加以说明,请执行以下操作:
相关问题 更多 >
编程相关推荐