Python中的print格式化用于将变量的值插入到字符串中,以便在输出时显示。它有以下几种用法:
name = "Alice"
age = 25
print("My name is %s and my age is %d" % (name, age))
name = "Alice"
age = 25
print("My name is {} and my age is {}".format(name, age))
name = "Alice"
age = 25
print(f"My name is {name} and my age is {age}")
这些方法都可以用来格式化打印输出,根据具体的需求选择适合的方法。