I have the following code, for example:
price = 50.00
tax = price * 0.08
print "Tax = $",tax # Tax = $ 4.0
As you can see there is a space between $ and 4.0. Is there a way to avoid this? I haven't done much Python coding.
I have the following code, for example:
price = 50.00
tax = price * 0.08
print "Tax = $",tax # Tax = $ 4.0
As you can see there is a space between $ and 4.0. Is there a way to avoid this? I haven't done much Python coding.
The simplest way would be to convert tax to a string and concatinate with a +. This avoids a comma, which adds one space.
price = 50.00
tax = price * 0.08
print "Tax = $",tax # Tax = $ 4.0
print "Tax = $"+str(tax) # Tax = $4.0
You should also look at the format string and it's % specifiers.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.