2014-01-29 30 views
0

如何改变,的默认值在下面的代码,以便它不插入空格如何更改Python中逗号的值?

gas = int(input("How much have you spent on gas? ")) 
electric = int(input("How much have you spent on electric? ")) 
onlinePurchases = int(input("How much have you spent on online purchases? ")) 
total = gas + electric + onlinePurchases 

print("Monthly Total: $", total) 

当前的代码将打印:

"Monthly total: $ *total*" 

有没有一种方法,使它打印:

"Monthly total: $*total*" 

我不希望美元符号和金额之间的空间。

回答

4

从蟒蛇printdocs

print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False) 

所以,你想

print("Monthly Total: $", total, sep='') 

更改sep从空间(分离)为空字符串

+0

谢谢你,只是让我知道是“月”短期的“分离”,如果没有这是什么立场? – user3131132

+0

这是正确的 – mhlester

3

print("Monthly Total: ${0}".format(total))

print("Monthly Total: $%d" % total)