f-string
python 中的字符串通常被括在双引号("")或单引号('')内。要创建 f-string,你只需要在字符串的开头引号前添加一个 f 或 F。例如,"This" 是一个字符串,而 f"This" 是一个 f-string。当使用 f-string 来显示变量时,你只需要在一组大括号 {} 内指定变量的名字。而在运行时,所有的变量名都会被替换成它们各自的值。语法如下所示:
author = "jane smith"
a_name = author.title()
print(f"This is a book by {a_name}.")
输出:
This is a book by Jane Smith.