【发布时间】:2020-07-27 16:33:29
【问题描述】:
我正在使用以下代码但出现错误
import re
text = 'some big text'
sentences = re.split('some splitter',text)
nsentences=len(sentences)
substring=[]
for i in range(nsentences):
substring.append[i]=re.split('some splitter',sentences[i]) #error line
print(substring[i])
TypeError: 'builtin_function_or_method' 对象不支持项目分配
【问题讨论】:
-
如果您希望项目位于
substring中的特定位置,则必须使用插入。append总是在末尾追加,是一个函数 -
substring.insert[i]=re.split('some splitter',sentences[i]) 同样的错误
-
and insert 也是一个函数,所以使用括号而不是括号。不妨看看:tutorialspoint.com/python/python_lists.htm
-
您有什么具体问题吗?请参阅How to Ask、help center。
标签: python