mystring = "Hi Python"
# Iterating through the string using while loop
for i in mystring[-1: -7 : -1] :
# Print all characters iterated
print("Element of string:" , i)
# Python code to reverse a string
# using loop
def reverse(s):
str = ""
for i in s:
str = i + str
return str
s = "HelloWorld"
print ("The original string is : ",end="")
print (s)
print ("The reversed string(using loops) is : ",end="")
print (reverse(s))
s = "SoftHunt" # initial string
reversedString=[ ]
index = len(s) # calculate length of string and save in index
while index > 0:
reversedString += s[ index - 1 ] # save the value of str[index-1] in reverseString
index = index - 1 # decrement index
print(reversedString) # reversed string