Can any explain me how end='' works here | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Can any explain me how end='' works here

def rev_str(my_str): length = len(my_str) for i in range(1,length): yield my_str[i] # For loop to reverse the string for char in rev_str("hello"): print(char, end= '') print() # Output: olleh

7th May 2020, 6:41 AM
Fanatic
Fanatic - avatar
2 Answers
+ 4
The end='' is used to remove the default line break of the print function. Example : for i in range(4): print(i) Output : 0 1 2 3 And if you do : print(i, end='') Output : 0123 Hope this helps :))
7th May 2020, 6:48 AM
Arb Rahim Badsa
Arb Rahim Badsa - avatar
7th May 2020, 9:58 AM
Fanatic
Fanatic - avatar