String slice arguments

Viewed 69

When 'teststring'[::-1] reverses the string, why can't we just write 'teststring'[1:4:-1] when I want output like 'tset'?

Any good sources to understand memory allocation and objects storage and other sources for python learning?

1 Answers

'teststring' [1: 4: -1] This example is incorrect because −1 all it does is return from the initial value to the secondary value and you can not put a smaller number in the first part and say return from 1 to 4

Also to get 'tset' from the 'teststring' string:

'teststring'[3::-1]
Related