0

I can reverse list order by using the reversed iterator or by using ::-1, as shown in this code:

li=[1,2,3]

print(list(reversed(li)))
print(li[::-1])

However, I have not understodde the meaning of the :: addressing, and I have not found any documentation on this feature (possible due to the fact that searching for :: creates problems).

Can anyone help? Thank you.

tfv
  • 6,016
  • 4
  • 36
  • 67

1 Answers1

1

That's an example of slicing. In Python, it's done like list[start:stop:step].Take a look at this SO answer for more details. In particular, note that the -1 is the step, meaning that it reverses how the list is traversed.

jss367
  • 4,759
  • 14
  • 54
  • 76