write a Python program to input the name and print the string in reverse order
Answers
Answered by
3
Answer:
Python program to input the name and print the string in reverse order
Explanation:
Python code to print the reverse of the string.
str = input("Enter a string: ")
## to take the input string by the user
print str[::-1]
## print the reverse of the input string
Output:
Enter a string: Reema
Ameer
Answered by
6
s = input("Enter a string: ")
print(s[::-1], "is its reverse.")
When using string slicing, the syntax is as follows:
string_name[start:end:step]
As the words suggest,
- start - indicates the starting character
- end - indicates the ending character
- step - indicates by how much each value must skip
It's also important to know the index values of each character as it's the index values that need to be placed in the slice range.
- If you skip the start and end values, by default, it will start at the first character and stop at the last character.
- When you give a negative value as the step value, the output is generated in reverse order.
For instance, if you were to run the program with the given codes above, it would produce a similar output:
Attachments:
Similar questions