1

I am new to python. Please anybody explain the following string operations

s="abcdefghijklmnop"

print s[:6][::-1] #is it first calculating s[:6] and then operating the result with [::-1] ?

Jan Vorcak
  • 18,421
  • 14
  • 49
  • 86
user2572943
  • 125
  • 1
  • 1
  • 9

1 Answers1

14
"abcdefghijklmnop"[:6][::-1]
  1. Take first 6 characters (abcdef).

  2. Read the result from the end to the beginning (fedcba).

There is an other better way to get this result:

"abcdefghijklmnop"[5::-1]
Happy
  • 1,802
  • 17
  • 33