2

Consider this one, if we are using slicing in python we have to pass three arguments in it [START:END: STEP] and if we don't want to insert index value in it they will consider by default in it like [0:-1:1].

HERE IS AN EXAMPLE:

PUTTING START INDEX VALUE:

s="DEEPAK"
print(s[0:5])
OUTPUT:
DEEPA

WITHOUT START INDEX VALUE:

s="DEEPAK"
print(s[:5])
OUTPUT:
DEEPA

Now my question is why in this example this logic is not working properly?

s="0123456789"
print(s[:-5:-5])
OUTPUT:
9


s="0123456789"
print(s[0:-5:-5])
OUTPUT:
Barmar
  • 741,623
  • 53
  • 500
  • 612

0 Answers0