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]
?
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]
?
"abcdefghijklmnop"[:6][::-1]
Take first 6 characters (abcdef
).
Read the result from the end to the beginning (fedcba
).
There is an other better way to get this result:
"abcdefghijklmnop"[5::-1]