Python错误:TypeError:“list”对象不是callab

2024-03-29 10:03:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我有这段代码:

count_words = input("Put in your favorite word, and then press the hidden button(SPOILER: IT'S ENTER!):")
split_Geonotes = Geonotes.replace ("\n", " "). split(".")
print (" Total number of words:", len (Geonotes.split() ) )

print("Total number of sentences:", len (Geonotes.split(".") ) )
print("Total number of periods:", Geonotes.count(".") )
print("you typed:", count_words)
print("There are:", Geonotes.count(count_words), "instances of", count_words)
split_Geonotes.sort()
print(split_Geonotes)
print("The number of elements in the HTML code:", len (split_Geonotes) )

for i in range(10):
    print(i)
    print(split_Geonotes(i) )

这导致了标题中显示的错误。 根据打印时发生的全部错误(一) 有人能告诉我怎么了吗? 谢谢您。


Tags: ofthe代码innumberinputlenput
1条回答
网友
1楼 · 发布于 2024-03-29 10:03:35

看起来您正试图将列表split_Geonotes索引到最后一行。为此,您需要使用方括号[...]

print(split_Geonotes[i])

括号(...)用于调用函数;当您将它们放在split_Geonotes之后时,Python将尝试调用列表:

>>> lst = [1, 2, 3]
>>> lst(0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'list' object is not callable
>>> lst[0]
1
>>>

相关问题 更多 >