【发布时间】:2019-09-10 18:26:39
【问题描述】:
我需要print(f"" + xx) 来输出text aaa,但它输出{x} 我怎样才能做到这一点?
我已尝试使用 printf 和 .format,但无法使其中任何一个工作
x = "aa"
xx = "text {x}"
x = "aaa"
print(f"" + xx)
【问题讨论】:
-
我不知道你想用那个代码完成什么。
-
xx必须在f" ... "块内,否则不会被插值 -
你的python版本是多少?如果低于 3.6,它将不起作用。由于格式化字符串文字是在 python 3.6 中添加的。 docs.python.org/3/whatsnew/…
标签: python python-3.x formatting printf string.format