我正在编写的代码字游戏(也称为替换字符)程序有问题,我不断地得到错误'str‘对象是不可调用的。这是我的代码(仅是while循环中与本词典相关的部分):
used_pairings = {}
while.....:
used_pairings[guesschar] = guessletter
print = ("At this point you can decide whether to delete a character-letter pairing.")
used_pairings_choice = input("Type 1 to delete a pairing or ENTER to carry on: ")
if used_pairings_choice == "1":
print ("These are your pairings so far:")
print (used_pairings)
else:
print ("Continuing program.")这是我得到的错误:
"Codeword.py", line 79, in <module>
print ("These are your pairings so far:")
TypeError: 'str' object not callable我完全不知道这意味着什么,以及为什么我会得到这个错误信息,所以任何帮助都将是非常感谢的。提前感谢!
发布于 2014-04-04 10:08:00
如果您正在使用python,3+ print是一个函数。当您执行print = ("At this point you can decide whether to delete a character-letter pairing.")时,您将使用一个字符串覆盖print内置函数。因此,只要将=从该行中删除,就可以修复它。
发布于 2014-04-04 10:07:50
问题是,print变量声明。
print = ("At this point you can decide whether to delete a character-letter pairing.")在这个语句之后,python的print函数将改为str (STRING)中的print变量。
请更改变量名并尝试您的代码。
https://stackoverflow.com/questions/22859575
复制相似问题