1

This is a shortened version of my function. My function is: def data(number): When you enter the number it'll end up showing a percentage as a float and some text behind it.

The next line is: print "total is: ", float(number), "%"

Which prints:

>>> data(22)
total is:  22.0 %

What I want to do is remove the space between the 22.0 and the %, so the result looks like this instead `

>>> data(22)
total is:  22.0%
karel
  • 5,489
  • 46
  • 45
  • 50
Replay22
  • 13
  • 2

1 Answers1

0

Each of the comma-delimited expressions that follows print will be separated by a space. One way to get control over that spacing is to use a format string. For example:

def data(number):
    print "total is %s%%" % float(number)

The %s in the format string becomes the string value of float(number) and the %% in the format string becomes a literal % character.

But you might also want to look into str.format(). There is a comparison between old-style format strings and new-style str.format() strings here.

davidrmcharles
  • 1,923
  • 2
  • 20
  • 33