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.
Table of Contents
show
Program Code
# 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)
Input Given:
Enter a string: moc.reppePudE
Output Expected:
EduPepper.com
Code Explanation
- The input string is split into a list of words using the
split()
method. - The list of words is iterated over using a for loop.
- Each word is reversed using the
[::-1]
slicing technique. - The list of reversed words is joined into a string using the
join()
method. - The resultant string is displayed.