You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何解决Python中'str' object is not callable错误?

问题解决办法

你的代码里有两个问题,直接导致了报错:

  • 打印函数大小写错误
    Python的内置打印函数是小写的print(),你写的Print()(首字母大写)不是系统自带的打印功能。而你碰到的'str' object is not callable报错,大概率是之前不小心把print这个内置函数名赋值成了字符串(比如写过print = "某个字符串"),这时候print就变成了字符串对象,无法被当作函数调用。

  • 字符串拼接可以简化
    你写的State_city = ('Abia' + 'Umuahia')完全可以简化为State_city = 'AbiaUmuahia',效果完全一致,没必要用加号和括号多此一举。

修正后的代码

State_city = 'AbiaUmuahia'
Together = State_city
print(Together)

额外处理方案

如果之前确实误将print赋值为字符串,要么重启Pydroid3的解释器,要么在代码中先删除错误赋值的变量:

del print  # 删除错误赋值的print变量
print(Together)  # 此时可正常调用内置print函数

内容的提问来源于stack exchange,提问作者Egwuatu Uchechukwu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.28 16:33:14