+ 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?

23rd Jan 2019, 4:28 PM
Abdul S Ansari
Abdul S Ansari - avatar
2 Answers
+ 5
Inside your loop: print(string[i], end=' ') (You can also use string of zero length ''.)
23rd Jan 2019, 4:35 PM
HonFu
HonFu - avatar
+ 4
btw 0 is the default start in range() so you can just say range(len(string))
23rd Jan 2019, 5:40 PM
David Ashton
David Ashton - avatar