在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)
比較: