How to Reverse String in Python || 6 Different Way || Python Programming

Published: 24 April 2020
on channel: Tech Guru Series
8,892
131

How to Reverse String in Python || 6 Different Way || Python Programming

Here is the code snippet..
day = "Sunday"
#Method-1 - Slicing
print(day[::-1])

#Method-2 - Using For Loop
temp = ''
for char in day:
temp = char + temp # Append chars in reverse order
print(temp)

#Method-3 - While Loop
temp = ''
length = len day -1
while length (greater= sign) 0:
temp = temp + day[length]
length = length -1
print(temp)

#Method-4- Using List - reverse()
day = "Sunday"
temp_list = list(day)
temp_list.reverse()
print(''.join(temp_list))

#Method-5 - Using Recursion
def reverse_rec(str):
if len(str) == 0:
return str
else:
return reverse_rec(str[1:]) + str[0]
print(reverse_rec("Sunday"))

#Method#6 - Reversed()
day = "Sunday"
reverse_str = ''.join(reversed(day))
print(reverse_str)


On this page of the site you can watch the video online How to Reverse String in Python || 6 Different Way || Python Programming with a duration of hours minute second in good quality, which was uploaded by the user Tech Guru Series 24 April 2020, share the link with friends and acquaintances, this video has already been watched 8,892 times on youtube and it was liked by 131 viewers. Enjoy your viewing!