For loop

Jabba Laci jabba.laci at gmail.com
Tue May 1 10:23:11 EDT 2012


Hi,

Try this:

import sys

for i in range (1, 5+1):
  for j in range (i):
    sys.stdout.write(str(i))
  print

"print" adds a newline character
print "hi",           notice the comma, it won't add newline, however
it adds a space
With sys.stdout.write you can print the way you want, it won't add any
extra stuff (newline or space).

Best,

Laszlo


On Mon, Apr 30, 2012 at 13:52, Daniel <daniel at kingdread.de> wrote:
> You could also try http://docs.python.org/library/stdtypes.html#str.join
> like this:
> for i in range(5):
>    print "".join(str(i) for j in range(i))
> --
> http://mail.python.org/mailman/listinfo/python-list



More information about the Python-list mailing list