我是使用3.7的Python新手,我正在尝试在整数变量前添加一个"$“。在执行了多次搜索之后,似乎有许多方法可以格式化字符串。我的目标是在print()中添加一个"$“。
我已经试过print('Total amount is' , houseAmount , ' of the house' , sep = ' $')
了。但没那么走运。
代码:
houseAmount = float(300000)
hoa = float(550.4)
print('House amount is' , houseAmount , ' for the house.' , 'HOA amount for the house is' , hoa , 'every year') (I would like to add a "$" before "houseAmount" and "hoa")
结果
House amount is $300000 for the house. HOA amount for the house is $550.4 every year
发布于 2019-06-10 00:37:10
print("House amount is ${} for the house. HOA amount for the house is ${} every year".format(houseAmount, hoa))
请记住,它是按顺序执行这些操作的。
https://stackoverflow.com/questions/56516377
复制相似问题