aguy01 aguy01 - 1 month ago 14
Python Question

whitespace in print statement - python v3.4

I want to print"After tax, your total is: $8.74999125."
no whitespace after $ sign.

how could I do this in this statement?

print("After tax, your total is: $",total_price).


The output of this statement adds whitespace after $.

total price is type float.

Answer

Convert total_price to string, then use string concatenations:

print("After tax, your total is: $" + str(total_price))

Or use strings formatting:

print("After tax, your total is: ${}".format(total_price))
Comments