Skip to content
Advertisement

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

Advertisement

Answer

Python 2

for x in xrange(1,11):
    print x,

Python 3

for x in range(1,11):
    print(x, end=" ") 
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement