我无法格式化这个字符串,为什么会这样
def poem_description(publishing_date, author, title, original_work):
poem_desc = "The poem {title} by {author} was originally published in {original_work} in {publishing_date}.".format(publishing_date, author, title, original_work)
return poem_desc
my_beard_description = poem_description("1897", "Tauqeer", "Venice", "1992")
print(my_beard_description)
花括号应为空
{}
。在花括号之间键入了变量。只要去掉它们,你就可以走了此外,您还可以使用格式化字符串
poem_desc = f"The poem {title} by {author} was originally published in {original_work} in {publishing_date}."
。字符串的前缀为f
,然后在字符串内部的花括号之间添加变量它应该是这样的:
或者像这样:
相关问题 更多 >
编程相关推荐