温馨提示×

Python中format()函数的嵌套使用示例

小樊
84
2024-08-26 10:16:17
栏目: 编程语言

name = "Alice"
age = 30
city = "Paris"

# 使用format()函数嵌套传入变量
message = "Hello, my name is {}. I am {} years old and I live in {}.".format(name, age, city)

print(message)

输出结果:

Hello, my name is Alice. I am 30 years old and I live in Paris.

0