+ 1
Please help me in Python!
I want to know how can I print in a single line in a for loop. Like: Code--- string = "string" for i in range (0, len(string)): print(string[i]) Output--- s t r i n g ------------- But I want string How can I do this?
2 Answers
+ 5
Inside your loop:
print(string[i], end=' ')
(You can also use string of zero length ''.)
+ 4
btw 0 is the default start in range() so you can just say range(len(string))