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)
In questa pagina del sito puoi guardare il video online How to Reverse String in Python || 6 Different Way || Python Programming della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Tech Guru Series 24 aprile 2020, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 8,892 volte e gli è piaciuto 131 spettatori. Buona visione!