python中格式化输出
时间: 2023-11-06 17:27:11 浏览: 74
Python中格式化输出可以使用字符串的format()方法或者f-string。下面是两种方法的示例:
使用format()方法:
```
age = 25
name = "John"
print("My name is {} and I am {} years old".format(name, age))
```
使用f-string:
```
age = 25
name = "John"
print(f"My name is {name} and I am {age} years old")
```
两种方法的输出结果都是:My name is John and I am 25 years old
阅读全文