0

How does this reversing works?

thislist = ["apple", "banana", "cherry", "orange", "kiwi", "melon", "mango"] print(thislist[::-1])

30th Jan 2021, 5:29 AM
zexu knub
zexu knub - avatar
3 odpowiedzi
+ 2
By index slicing: Parameters: --> thislist[ start : end : steps ] Default Value: start = 0 end = len(list) steps = 1 thislist[ : ] means from 1st element to last element (all) thislist[ : : -1 ] --> Here we have added a new argument, which is the step. And when step is negative, the step is backwards. In words "From first element to last element, backwards" In result, the list or string or any iterables will be reversed.
30th Jan 2021, 5:36 AM
noteve
noteve - avatar
+ 1
The first one is the starting point (before the colon, the middle one is the range,and the third part is the updation. -1 indicates backward or reversing in python. This process is called as slicing
30th Jan 2021, 5:35 AM
Atul [Inactive]
0
r=input() print(r[::-1]) Input =tree output=eert See this is the example
30th Jan 2021, 5:36 AM
Atul [Inactive]