0
How do ::-1 works as a list operator for reversing it?
Didn't get the sense of ::
5 ответов
+ 1
List[start:end:step] so here ::-1 means the step is - 1 which will go backwards from the end to the start and give you the reverse
+ 3
This used to print all elements of a list from the last element to the first element
+ 2
In a list, when you try to access an element, you would use the square brackets, in python, they have a lot of fonctionality, they can get an index "[5]", get you a range "[5:10]" and get a range with steps "[5:11:2]". Those option can be optional, for exemple, "[:10]" will give get you all element from start to 10. so this is why you only see "::-1" writen this way, it means from start to end with a negative step wich will reverse the order.
+ 2
In slice [A:B:C] you add C to A until A = B.
If the new slice would never be achieveable, it gives an empty slice.
+ 1
Wow, that took 7 minutes to get an answer! So kind and quick♥