[Tutor] blank space after a number

Hugo Arts hugo.yoshi at gmail.com
Tue Dec 28 20:31:28 CET 2010


On Tue, Dec 28, 2010 at 2:54 PM, Enih Gilead <egilead at gmail.com> wrote:
> Hi, Abrahamsen!
>
> Would you mind tell me a way to eliminate the blank space in front of "a"
> [int number] ?
> Just as an example, the 'a' that is made = to '0', when printed, it comes
> with a blank space after...
>
> a, b = 0, 1
> while b < 10:
>    print a, b,
>    a, b = a, b + 1
>
> ... do you think is there any reasonable way to transform the '0' number
> into string and then back to numeral - after the printing action?
>

If you put commas between things in a print statement, python will put
a space in between. Either use string formatting or convert to str()
and add together:

print "{0}{1}".format(a, b),
print str(a) + str(b),

Hugo


More information about the Tutor mailing list