[::-1] in Python | What is the meaning of a[::-1] in Python?

The Slice notation in python has the syntax –

list[<start_index>:<stop_index>:<step>]

So, when you do,a[::-1] it starts from the end, towards the first, taking each element. So it reverses a. This is applicable for string/lists/tuples as well.

Example –

>>> a = '12325'>>> a[::-1]'52321'