Reverse Words of any string – Python Code
Let us create a program in python that accept on a string from the keyboard and print the whole string in reverse order. It should not reverse the words, it should only reverse the order of these words.
A sample run of the program
Enter your string: hello Rakesh how are you doing
Output: doing you are how Rakesh hello.
Solution Program to display string in reverse order
# Program to read a string in a variable and print all its contents in reverse order # program by : rakesh kumar # website : https://cbsetoday.com word = input('Enter any large string : ') print('Original string :',word) word = word.split() word = ' '.join(word[-1::-1]) print('Reverse String :',word)
The above program accept one string in a variable word and then split this string into words using the string split() method. Split method is again joined using join( ) function but taking all the elements from the back.