alphabet='abide'
>>>alphabet[-1::-1]
'ediba'
>>>alphabet[::-1]
'ediba'
Why did this two print out the same thing? Shouldn't the second one be 'aedib'?
alphabet='abide'
>>>alphabet[-1::-1]
'ediba'
>>>alphabet[::-1]
'ediba'
Why did this two print out the same thing? Shouldn't the second one be 'aedib'?
alphabet[::-1]
Will reverse your string. Why? There is no value before the first colon, so it stats at the beginning index of the list. Then, still no value, so you go all the way to the end of the list. Third, you have -1
, so you increment by -1, in other words you are going backwards.
It is equivalent to alphabet[-1::-1]
since you just ask to start from the final character, which it already does.