0
How does this reversing works?
thislist = ["apple", "banana", "cherry", "orange", "kiwi", "melon", "mango"] print(thislist[::-1])
3 Respuestas
+ 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.
+ 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
0
r=input()
print(r[::-1])
Input =tree
output=eert
See this is the example