相关疑难解决方法(0)

python-3.6中带有'f'前缀的字符串

我正在尝试使用Python 3.6.通过新代码,我偶然发现了这个新语法:

f"My formatting string!"
Run Code Online (Sandbox Code Playgroud)

看来我们可以这样做:

>>> name = "George"
>>> print(f"My cool string is called {name}.")
My cool string is called George.
Run Code Online (Sandbox Code Playgroud)

任何人都可以对这个内部运作有所了解吗?特别是f前缀字符串可以采用的变量范围是多少?

python scope string-formatting python-3.6 f-string

52
推荐指数
3
解决办法
2万
查看次数

标签 统计

f-string ×1

python ×1

python-3.6 ×1

scope ×1

string-formatting ×1