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

preview_player
Показать описание
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)
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)
Рекомендации по теме
Комментарии
Автор

Great video! Gets right to the point, thank you.

sukhmanisahaji
Автор

thank you sir for such a nice video
sir can u please make a video series of python

shraddhagupta
join shbcf.ru