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.
Answers:
I would use string formatting
print("After tax, your total is: ${}".format(total_price))
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))
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='').
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.
I would use string formatting
print("After tax, your total is: ${}".format(total_price))
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))
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='').