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

Publicado em: 24 Abril 2020
no canal de: 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)


Nesta página do site você pode assistir ao vídeo on-line How to Reverse String in Python || 6 Different Way || Python Programming duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário Tech Guru Series 24 Abril 2020, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 8,892 vezes e gostou 131 espectadores. Boa visualização!