values = []
values.append(1)
values.append(3)
values.append(5)
print('first time:', values)
values = values[1:]
print('second time:', values)
Will produce the required results.
The list values[low:high]
has high - low
elements. For example, values[1:4]
has the 3 elements values[1]
, values[2]
, and values[3]
. Note that the expression will only work if high
is less than the total length of the list values
.
m
.-1
.-N
, which represents the first element.del values[-N]
removes the first (zeroth) element from the list.values[:-1]
lithium
lithium
to the variable element
. Which displays nothing.print
the slice lithium[0:20]
Python returns lithium
which is element[1:]
and element[-1:20]
which is just an empty slice, there is nothing else to display.element[-1:3]
nothing is printed because the low
value -1
is bigger, as an index than the high
value 3
. So the slice is empty