def reverse(s):
str = ""
for i in s:
str = i + str
return str
s = "Geeksforgeeks"
print ("The original string is : ",end="")
print (s)
print ("The reversed string(using loops) is : ",end="")
print (reverse(s))
I tried the code in my own way to understand how the above method is reversing the string entered in s
in my own way
i will post what i tried to know where I have gone wrong in my understanding
s='preetham'
for i in s:
str=''
s=i+str
print(s)
I tried the above code to just understand what role is i and str playing in helping the code to reverse the string, as I predicted from my understanding the above code should print the following output
p
r
e
e
t
h
a
m
*