小册名称:Python合辑5-格式化字符串
F-string也能计算稍微复杂的运算式,比如if/else
>>> a = "this is a">>> b = "this is b">>> f"{a if 10 > 5 else b}"'this is a'>>> f"{a if 10 < 5 else b}"'this is b'
>>> a = "this is a"
>>> b = "this is b"
>>> f"{a if 10 > 5 else b}"
'this is a'
>>> f"{a if 10 < 5 else b}"
'this is b'