I can't find any information on [::-1]
. In the wikibooks python tutorial, there is a section about non-continous lists, but there's no information on parameters < 0. Effects are clear, but how do you explain it?
Example Usage:
>>> foo = [1, 2, 3]
>>> foo[::-1]
[3, 2, 1]
The syntax is as follows:
foo[start:end:step] # begin with 'start' and proceed by step until you reach 'end'.
So foo[::-1]
means entire list with step=-1
, so actually reversing the list.
See this answer for detailed explanation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With