Python “错误”;并非所有参数都在字符串格式化过程中转换;这里怎么了?

Python “错误”;并非所有参数都在字符串格式化过程中转换;这里怎么了?,python,python-3.x,Python,Python 3.x,.format()是一种字符串方法。您需要在模板字符串上调用它: name = input ("What is your name?") quest = input("What is your quest?") color = input ("what is your favorite color") print ("Ah, so your name is {}, your quest is{}, and your favorite color is{}.")str.format(name,

.format()
是一种字符串方法。您需要在模板字符串上调用它:

name = input ("What is your name?")
quest = input("What is your quest?")
color = input ("what is your favorite color")

print ("Ah, so your name is {}, your quest is{}, and your favorite color is{}.")str.format(name, quest, color)

请注意
.format()
是如何紧跟在
的“啊,那么…就是{}.”
字符串定义之后的,并且该方法的结果将传递给
打印(…)
函数进行打印。

您需要为
.format
提供参数号。试试下面


打印(“啊,那么你的名字是{0},你的任务是{1},你最喜欢的颜色是{2}。”.format(name,quest,color))

你为什么叫str.format?只需使用yourstring.format(…format方法将在
上被调用,“啊,那么…就是{}。”
string。不是在
str
类型上。您的代码从
str.format…
开始有语法错误,因此它不能有您声称的错误。请测试您的代码并发布产生错误的演示。这可能是一些愚蠢的事情,但我们被另一个愚蠢的事情阻止了。
print("Ah, so your name is {}, your quest is{}, and your favorite color is{}.".format(name, quest, color))