Python Newbie?

prices=["Apple",90,"Mango",70,"Banana",45]
prices=[["Apple",90],
["Mango",70],
["Banana",45]]
prices=["Apple",90,"Mango",70,"Banana",45]
prices[0] #output="Apple"
prices[3] #output=70
price[-1] #output=45
price[-3] #output=70
prices[1:3] #[90,"Mango"]
prices[2:5] #["Mango",70,"Banana"]
prices[:3] #["Apple",90,"Mango",70,"Banana",45]
prices[4:] #["Banana",45]
prices=[["Apple",90],
["Mango",70],
["Banana",45]]
prices[1][0] #output="Mango"
prices[2][1] #output=45

List Manipulation:

we can update the list at our will like adding or removing elements from list and we can replace lists values as well, for updating a value we simply use assignment operator where for removing a value from list we use del(variable_name) function.

final_prices =prices+[["strawberry",110]]
del(final_prices[3])
final_prices[1][1] = 120

--

--

Data Scientist who loves to teach machine through data.

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store