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
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 :))
0
Arb Rahim Badsa thanx