Python - 将格式化数字添加到字符串

The*_*Woo 1 python string format

使用Python v2,我有以下代码:

print ("Total of the sale is: ${:,.2f}".format(TotalAmount))
Run Code Online (Sandbox Code Playgroud)

这是一个名为"TotalAmount"的字符串,并将其格式化为如下所示:$ 100.00,即:货币值,无论数字是多少.

有没有办法将格式化的输出写入字符串?

谢谢你的帮助.

Hug*_*ell 5

yourVar = "Total of the sale is: ${:,.2f}".format(TotalAmount)
Run Code Online (Sandbox Code Playgroud)