字符串格式化:在字符串中使用字母"f"作为前缀,可以创建格式化字符串。这种格式化方式被称为f-string。在f-string中,可以通过在大括号内包含表达式来引用变量值,这些表达式会在运行时被求值并嵌入到字符串中。例如:
name = "Alice"
age = 25
message = f"My name is {name} and I am {age} years old."
print(message) # 输出:"My name is Alice and I am 25 years old."