显示金额 - Python

时间:2015-02-28 13:33:56

标签: python printing currency

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

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

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

import.locale吗?

2 个答案:

答案 0 :(得分:1)

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

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

答案 1 :(得分:1)

使用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)))