如何在python 3中打印没有空格?

时间:2015-04-09 02:35:46

标签: python

>>> income = 50
>>> print("Your income tax is $",income,".")
Your income tax is $ 50 .

那么如何打印" 50美元。"一起?

3 个答案:

答案 0 :(得分:1)

您可以使用sep参数进行打印:

>>> income = 50000
>>> print("Your income tax is $", income, ".", sep='')
Your income tax is $50000.

或使用str.format

>>> print("Your income tax is ${}.".format(income))
Your income tax is $50000.

答案 1 :(得分:0)

使用string formatting

print("Your income tax is ${0}.".format(income))

答案 2 :(得分:0)

您也可以这样做:

x = 50
x = str(x)
y = 'Your Income is $'
z='.'
print(y+x+z)

输出: 你的收入是50美元。