在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)
比较:
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:format与f-string有何区别