In [1]: print( "hello world") hello world In [2]: print( " i %d x %g " % (3, 3.14)) i 3 x 3.14 In [3]: a = 12.345678901234 In [4]: print( "%s" % "{}".format(a)) 12.3456789012 In [5]: print( repr(a)) 12.345678901234 In [6]: print( "%g" % a) 12.3457
Whenever print thinks that the current writing position is somewhere in the middle of a line, it adds a leading blank. This can be avoided by using sys.stdout.write.