Python错误:TypeError:'list'对象不可调用

时间:2014-04-27 22:54:37

标签: python html tags typeerror python-3.3

我有这段代码:

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) )

会产生标题中显示的错误。 根据完整错误,它发生在print(i) 有人可以向我解释一下是什么错吗? 谢谢。

1 个答案:

答案 0 :(得分:0)

看起来您正试图在最后一行索引列表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
>>>