Search
 
SCRIPT & CODE EXAMPLE
 

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] 
Comment

PREVIOUS NEXT
Code Example
Python :: count nan values 
Python :: - inf in python 
Python :: read and write to file python 
Python :: matplotlib figure size not working 
Python :: python function vs lambda 
Python :: python get local ipv4 
Python :: __str__ method python 
Python :: get all files in pc python 
Python :: add new row to dataframe pandas 
Python :: python remove last instance of a list 
Python :: generate binary number in python 
Python :: csv len python 
Python :: python convert int to hex string 
Python :: get ip address python 
Python :: How to Get the Intersection of Sets in Python 
Python :: How to store the input from the text box in python 
Python :: how to select top 5 in every group pandas 
Python :: python defaultdict to dict 
Python :: Matplotlib inside Jupyter | Jupyter generate graphs. 
Python :: python extract substring 
Python :: pandas convert string column to int list column 
Python :: remove part of string python 
Python :: numpy random choice 
Python :: seaborn barplot remove error bars 
Python :: python add comma each 3 digits format 
Python :: Invalid password format or unknown hashing algorithm. 
Python :: reset index in pandas 
Python :: regex for repeating words python 
Python :: list in list python 
Python :: prime numbers python 
ADD CONTENT
Topic
Content
Source link
Name
5+1 =