Reverse a string in Python
Use slicing with a step of -1. Press Run to try it, then change the code and run it again.
main.py
text = "CodingHumans"
print(text[::-1]) # snamuHgnidoC
Output
Press Run to see the output.
More Python examples
- Hello, World · Print a line of text.
- Check a prime number · Test divisors up to the square root of the number.
- Fibonacci series · Print the first n Fibonacci numbers with a generator.
- Add numbers from input · Read several numbers on one line and add them up.
- Count words with a dictionary · Count how often each word appears.