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

如何在Python字符串中间插入用户输入内容?

解决方法

你的错误在于把print()的返回值当成了函数调用——print()执行后返回None,你写print("Wow")(...)相当于尝试调用None(),这就会触发NoneType is not callable错误。

下面是三种能实现你需求的写法:

方法1:利用print的多参数特性(最简便)

print可以接受多个参数,默认用空格分隔并在同一行输出:

name = input("Name? ")
print("Wow", name, "that's cool")

方法2:使用f-string格式化(最直观)

Python 3.6及以上版本支持f-string,直接把变量嵌入字符串的{}中:

name = input("Name? ")
print(f"Wow {name} that's cool")

方法3:字符串拼接

用+连接多个字符串,注意手动添加空格保证格式正确:

name = input("Name? ")
print("Wow " + name + " that's cool")

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.11 20:40:25