首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TypeError:“str”对象不能用于在while循环中打印字典

TypeError:“str”对象不能用于在while循环中打印字典
EN

Stack Overflow用户
提问于 2014-04-04 10:00:46
回答 2查看 1.4K关注 0票数 1

我正在编写的代码字游戏(也称为替换字符)程序有问题,我不断地得到错误'str‘对象是不可调用的。这是我的代码(仅是while循环中与本词典相关的部分):

代码语言:javascript
复制
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.")

这是我得到的错误:

代码语言:javascript
复制
"Codeword.py", line 79, in <module>
    print ("These are your pairings so far:")
TypeError: 'str' object not callable

我完全不知道这意味着什么,以及为什么我会得到这个错误信息,所以任何帮助都将是非常感谢的。提前感谢!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-04-04 10:08:00

如果您正在使用python,3+ print是一个函数。当您执行print = ("At this point you can decide whether to delete a character-letter pairing.")时,您将使用一个字符串覆盖print内置函数。因此,只要将=从该行中删除,就可以修复它。

票数 5
EN

Stack Overflow用户

发布于 2014-04-04 10:07:50

问题是,print变量声明。

代码语言:javascript
复制
print = ("At this point you can decide whether to delete a character-letter pairing.")

在这个语句之后,python的print函数将改为str (STRING)中的print变量。

请更改变量名并尝试您的代码。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22859575

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档