Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Reversing a String
#1
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.
Reply
#2
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  reversing strings westbob 4 2,600 Jun-11-2019, 04:11 PM
Last Post: buran
  reversing a string kerzol81 3 2,807 Jul-18-2018, 09:24 PM
Last Post: perfringo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020