Logic Building
# Take string input
s = input("Enter a string: ")
# Reverse string
reversed_str = s[::-1]
print(f"Reversed: {reversed_str}")Output
Enter a string: Hello Reversed: olleH
Use slicing with step -1 to reverse string.
Key Concepts:
s[::-1]reverses the string- Start:end:step notation
- Step -1 goes backwards