Print range of numbers on same line
Using python I want to print a range of numbers on the same line. how can I do this using python, I can do it using C by not adding n
, but how can I do it using python.
for x in xrange(1,10):
print x
I am trying to get this result.
1 2 3 4 5 6 7 8 9 10
for x in xrange(1, 10):
print x,
>>>print(*range(1,11))
1 2 3 4 5 6 7 8 9 10
Python单行打印范围
在这种情况下, str.join
将是合适的
>>> print ' '.join(str(x) for x in xrange(1,11))
1 2 3 4 5 6 7 8 9 10
链接地址: http://www.djcxy.com/p/53552.html
上一篇: Python 3:用星号表达来解压缩列表
下一篇: 在同一行上打印数字范围