whitespace in print statement – python v3.4

Question:

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.

Asked By: aguy01

||

Answers:

I would use string formatting

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

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))
Answered By: Uriel

Third variant: it is also possible to change separator symbol (to empty string in current case):

print("After tax, your total is: $",total_price, sep=''). 
Answered By: Andrew
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.