Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

list -1 python

l = [1,2,5,9,7,4,5]

# what are you referring to?
# 1) l[-1] is the last element of list
print(l[-1])
>>> 5

# 2) l[:-1] returns all the elements of the list but the last one
print(l[:-1])
>>> [1,2,5,9,7,4] 
 
PREVIOUS NEXT
Tagged: #list #python
ADD COMMENT
Topic
Name
8+3 =