The reverse words in a string

In this program, we will take a string as input and reverse words in a string

Steps to solve the program
  1. Take a string as input.
  2. First split the string using split() and then reverse the words using reversed().
  3. Print the output.
				
					#Input string
str1 = "string problems"

#Input strinh
print(" ".join(reversed(str1.split(" "))))
				
			

Output :

				
					problems string
				
			

add ly at the end of the string if the given string ends with ing.

print the index of each character in a string.

Leave a Comment