Strings are sequences of characters. They can be enclosed in quotation marks to make them appear as a single unit, and they can be accessed in several ways.
# Get input string input_str = input("Enter a string: ") # Split the input string into a list of words words = input_str.split() # Reverse each word in the list words = [word[::-1] for word in words] # Join the list of words into a string output_str = " ".join(words) # Display the resultant string print(output_str)
Enter a string: moc.reppePudE
- The input string is split into a list of words using the
- The list of words is iterated over using a for loop.
- Each word is reversed using the
- The list of reversed words is joined into a string using the
- The resultant string is displayed.