-2

I'm new to python, I should convert the following operation in php:

if len (s) == 88:
    return s[48] + s[81:67: -1] + s[82] + s[66:62: -1] + s[85] + s[61:48 : -1] + s[67] + s[47:12: -1] + s[3] + s[11:3: -1] + s[2] + s[12]

I do not understand exactly what you mean this formatting s[a:b: -c].

Ashwini Chaudhary
  • 244,495
  • 58
  • 464
  • 504

1 Answers1

0
s = "012345678910"
a = 7
b = 4
c = 1
print s[a:b: -c]

returns:

765

So to explain, its a slice between position 7 in the string and position 4, first element is element 0, in steps of minus one. That is to say, you get every element between 7 and 4 not including 4.

The general form of a slice as detailed in the docs is slice(start, stop[, step]).

Noelkd
  • 7,686
  • 2
  • 29
  • 43