Python Forum

Full Version: Reversing a String
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi Viewer,

Just started learning to code in Python. Was going thru some code online on reversing a string. The code is as follows:

s = "Hello"
print(s[::-1])

Could not understand the underlying logic behind this? Is this something builtin which Python by default understands like for instance s[::] would print the complete string. Please clarify.

Thanks,
Kiran.
This uses what is called an extended slice. I can't explain it as well as the documentation, so see: https://docs.python.org/2/whatsnew/2.3.h...ded-slices