将字典的值注入打印格式

Injecting the Value of Dictionary into print formatting

如何在 Python 中使用字符串插值将字典的值注入字符串?

airports = {"key":"value"} 
message = f"{airports["key"]}" // this gives a syntax error 

使用 Python 3.7

字符串需要使用单引号,

airports = {"key":"value"} 
message = f'{airports["key"]}'

实现此目的的另一种方法是,

airports = {"key":"value"}
valToPrint = airports["key"]
message = f'{valToPrint}'