python格式化输出类
时间: 2023-05-21 14:00:48 浏览: 97
可以使用字符串的 format() 方法来进行格式化输出,例如:
```
name = "Alice"
age = 25
print("My name is {}, and I am {} years old.".format(name, age))
```
输出结果为:
```
My name is Alice, and I am 25 years old.
```
你也可以使用 f-string 来进行格式化输出,例如:
```
name = "Alice"
age = 25
print(f"My name is {name}, and I am {age} years old.")
```
输出结果同样为:
```
My name is Alice, and I am 25 years old.
```
阅读全文