17. List Slicing - Help me understand this


Hey everyone, after some tries and a bit of research I managed to make code work. Can someone help me understand why the "X" 's disappear after I write "message = garbled[len(garbled)::-2]"? I am pretty sure it's an easy answer but I'm a bit confused here, thanks!

garbled = "!XeXgXaXsXsXeXmX XtXeXrXcXeXsX XeXhXtX XmXaX XI"
message = garbled[len(garbled)::-2]
print message



They don't disappear as the original string is not modified (and it can't be, because strings are not mutable). Have you considered what each parameter in the slicing syntax do? It'll be evident why the X's are not included when you do. The parameters are my_list[start:stop:step]


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.