Reversing a list by slicing | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
0

Reversing a list by slicing

I learned that using [::-1] reverses a list. But if I am not wrong, the first argument in [ : : ] is by default 0, i.e. start of list and second argument is by default end of list i.e., -1. So shouldn't [::-1] just return the first element followed by the last?

30th Mar 2020, 9:00 AM
Ram Keswani
Ram Keswani - avatar
1 Respuesta
0
-1 is the step i.e [start:end:step] [::-1] means From the first argument in the list to the last with a step of -1.
30th Mar 2020, 9:06 AM
Justus
Justus - avatar