使用句法:
>>> name = "Eric" >>> age = 74
>>> f"Hello, {name}. You are {age}."在实际应用里的使用:
1、调用函数
>>> def to_lowercase(input):
... return input.lower()
>>> name = "Eric Idle"
>>> f"{to_lowercase(name)} is funny."
'eric idle is funny.'2、调用对象
>>> f"{name.lower()} is funny."
'eric idle is funny.'注意,因为F-Strings 在调用函数过程中,尤其是运行的时候,需要将表达式放在自己的作用域里进行计算求值才可以。