0
mystr="Hello I am kumar gaurav"
print(mystr[0:9:-1])

When I write this inside print() so no any answer is performed, why? Please explain to me why it is happening there. I do not understand this code.

MatthewMartin
  • 32,326
  • 33
  • 105
  • 164

2 Answers2

0

according to this [start, stop, step] you slicing your string from 0 indexes to 9 indexes but through the step of -1(step means Jump -1 step). so this means when start is 0 you told to go back one step and there's no character behind o indexes('H').

use this

print(mystr[0:9][::-1]) // to reverse
KayseMca
  • 40
  • 1
  • 6
0

sir suppose my question is myst= "Hello kumar gaurav" print(myst[0::-1]) here we also start from 0 then why first character is print. can u explain the difference between this question and previous question..