1

Example code:

name = "i am a student"
print(name[::-1])

Output:

tneduts a ma i
Mr. Discuss
  • 355
  • 1
  • 4
  • 13
  • have a look here to: https://stackoverflow.com/questions/493046/i-dont-understand-slicing-with-negative-bounds-in-python-how-is-this-supposed – CK__ Sep 06 '20 at 17:13

2 Answers2

1

The last part of a slice denotes steps:

sequence[start:stop:steps]

As the last part is steps, it goes on the string on steps of -1:

i am a student
             ^
i am a student
            ^
i am a student
           ^
Bharel
  • 23,672
  • 5
  • 40
  • 80
0

String_index[start:stop:step] You set the start to 0 and the end to the last element and the step -1 which mean its gonna go from first to last but reversed

Geralt
  • 3
  • 2