Let’s write a program to reverse the full string.
str = 'Hello My name is python, enjoy your day'
print (str)
# Solution 1
lst = str[::-1]
print (lst)
# Solution 2
lst_1 = list(str)
print (lst_1)
lst_1.reverse()
print (lst_1)
reverse_str = ('').join(lst_1)
print (reverse_str)
Output:
Hello My name is python, enjoy your day
yad ruoy yojne ,nohtyp si eman yM olleH
['H', 'e', 'l', 'l', 'o', ' ', 'M', 'y', ' ', 'n', 'a', 'm', 'e', ' ', 'i', 's', ' ', 'p', 'y', 't', 'h', 'o', 'n', ',', ' ', 'e', 'n', 'j', 'o', 'y', ' ', 'y', 'o', 'u', 'r', ' ', 'd', 'a', 'y']
['y', 'a', 'd', ' ', 'r', 'u', 'o', 'y', ' ', 'y', 'o', 'j', 'n', 'e', ' ', ',', 'n', 'o', 'h', 't', 'y', 'p', ' ', 's', 'i', ' ', 'e', 'm', 'a', 'n', ' ', 'y', 'M', ' ', 'o', 'l', 'l', 'e', 'H']
yad ruoy yojne ,nohtyp si eman yM olleH