代码示例:(标识:python_string_formatting_4)
python_string_formatting_4.py
quantity = 3
itemno = 567
price = 52
myorder = "I want {0} pieces of item number {1} for {2:.2f} dollars."
print(myorder.format(quantity, itemno, price))
运行结果: