Languages
[Edit]
EN

Python - reverse a string

0 points
Created by:
Teilsa
345

In this article, we would like to show you how to reverse a string in Python.

Quick solution:

reversed_string = string[::-1]

Where the statement [::-1] means:

  1. start at the end of the string,
  2. end at position 0,
  3. move with the step -1 (step backwards)

 

Practical example

In this example, we use a slice that steps backwards to reverse the string.

string = "ABC"
reversed_string = string[::-1]

print("Original string:", string)
print("Reversed string:", reversed_string)

Output:

Original string: ABC
Reversed string: CBA

Python - string (popular problems)

Python - reverse string
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join