fruit = “string”
nums = [1,2,3,4]
nums[::-1] will reverse the list!
In Python, the expression nums[::-1]
is used to reverse a list or any other sequence. Let's break it down:
nums
refers to the list that you want to reverse.:
indicates that you want to select a slice of the list.:
is used to specify the step size. In this case, the step size is 1
, which means you want to traverse the list in reverse order.[::-1]
part specifies the start and end indices for the slice. Since no start or end indices are provided, the default values are used, which means you want to select the entire list.