在Python中,可以使用format函数或者f-string来进行字符串格式化。
name = "Alice"
age = 30
message = "My name is {} and I am {} years old.".format(name, age)
print(message)
name = "Alice"
age = 30
message = f"My name is {name} and I am {age} years old."
print(message)
比较: