Search code examples
pythonpython-3.xoperators

How to do this without double operators?


I was trying to print some numbers within a certain range horizontally using for loop with double operators(+=)

str_1=''
for i in range(10): 
    str_1 += str(i)+" " 
print(str_1)

The output shows as :

0 1 2 3 4 5 6 7 8 9

How to print this output without double operators(+=)?


Solution

  • The answer from @chepner in the comments solved my problem. Thanks to everyone for participating.

    str_1 = str_1 + str(i) + " "