为什么python F字符串模块不起作用?

时间:2019-07-01 17:53:31

标签: python python-3.x format

我正在用python 3.7.3开发一个冒险游戏,并且我在某些打印语句中使用了F字符串。在终端中运行它并升华文本时,F字符串给我一个错误。

template <>
struct JustEqual<Nothing, Nothing> : public std::true_type
 { };

3 个答案:

答案 0 :(得分:0)

f("You ...)中,您正在调用名为f的函数,该字符串为输入参数,但没有这样的函数,因此会出错。

您需要删除括号()使其成为f字符串:

f"You are the mighty hero {name}. In front of you, there is a grand palace, containing twisting marble spires and spiraling dungeons.\n"

答案 1 :(得分:0)

f字符串不是使用函数创建的,它是一种字符串,您使用f''表示(类似于b''r''

所以尝试使用:

printfast(f"You are the mighty hero {name}. In front of you, there is a grand palace, containing twisting marble spires and spiraling dungeons.\n")

答案 2 :(得分:0)

您做错了。 f不是一个函数,它更多是一个语法标识符。常规引号"表示常规字符串的开头(或任何类型的字符串的结尾),而标记f"则特别指示格式字符串的开头。对于用r"表示的原始字符串或用b"表示的二进制字符串也有相同的想法。

代替

f("You are...")

f"You are..."