众所周知,在 Python f 字符串中使用 {} 可以执行代码片段并以 string
格式给出结果( 此处 提供一些教程)。但是,表达式末尾的“ = ”是什么意思?
log_file = open("log_aug_19.txt", "w")
console_error = '...stuff...' # the real code generates it with regex
log_file.write(f'{console_error=}')
原文由 ibarrond 发布,翻译遵循 CC BY-SA 4.0 许可协议
这实际上 是 Python 3.8 的一个全新特性。
本质上,它促进了打印调试的频繁用例,因此,而我们通常必须编写:
我们现在可以写:
因此,作为演示,使用全新的 Python 3.8.0 REPL: