xxxxxxxxxx
# 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))
xxxxxxxxxx
# in order to make a string reversed in python
# you have to use the slicing as following
string = "racecar"
print(string[::-1])
xxxxxxxxxx
#linear
def reverse(s):
str = ""
for i in s:
str = i + str
return str
#splicing
'hello world'[::-1]
xxxxxxxxxx
reversed_string = input_string[::-1]
xxxxxxxxxx
# Function to reverse a string
def reverse(string):
string = string[::-1]
return string
s = "Geeksforgeeks"
print("The original string is : ", end="")
print(s)
print("The reversed string(using extended slice syntax) is : ", end="")
print(reverse(s))