J
Ju Hui
I want to print 3 numbers without blank..... print x
....
0
1
2.... print x,
....
0 1 2
how to print
012
?
thanks.
....
0
1
2.... print x,
....
0 1 2
how to print
012
?
thanks.
Ju said:I want to print 3 numbers without blank.
... print x
...
0
1
2
... print x,
...
0 1 2
how to print
012
?
thanks.
I want to print 3 numbers without blank. [snip]
how to print
012
?
.... L.append(str(x))L = []
for x in range(3):
print ''.join([str(x) for x in range(3)]) 012
I want to print 3 numbers without blank. [snip]
how to print
012
?
Method one: accumulate your numbers into a single string, then print
it in one go.
... L.append(str(x))L = []
for x in range(3):
...
Or even:
Or use a list comprehension:
print ''.join([str(x) for x in range(3)]) 012
Method two: don't use the print statement, but write directly to
standard output.
... sys.stdout.write(str(x))
...
012>>>
But notice how this does not write a newline when you are done -- you
will have to remember to do it yourself with sys.stdout.write('\n').
Also, print will work with any object, but sys.stdout.write will only
work with strings:
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: argument 1 must be string or read-only character buffer,
not int
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.