显示金额 - Python

Displaying amount - Python

print("The cost of paint based on whole gallons is: $", round(paint_costs,2))
The cost of paint based on whole gallons is: $ XXX.XX

如何省略 $ 和金额之间的 space,使其显示为:

The cost of paint based on whole gallons is: $XXX.XX

import.locale吗?

在打印函数中添加 sep="" 参数。

print("The cost of paint based on whole gallons is: $", round(paint_costs,2), sep="")

使用 Py3 功能sep

print("The cost of paint based on whole gallons is: $", round(paint_costs,2),sep = "")

其他方式包括

  • print("The cost of paint based on whole gallons is: ${}".format(round(paint_costs,2)))
  • print("The cost of paint based on whole gallons is: $%s"%(round(paint_costs,2)))