Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Get items of list with number

So I created a list and I need to get items of that list with number like

myList = {Baseball,Basketball,Football}
print(myList.getitem(3)) #this should print item 3 of myList

can anyone help me?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

So, first off lists in python are bounded by square brackets. Also, I’m assuming Basketball and Football are variables you’ve already defined in your script, so you’ll have something that looks like this:

Basketball = 5
Football = 'a'

myList = [Basketball, Basketball, Football]

You can get the value of the third item of this list using an index! Indexing counts from 0, so we’ll be calling for index 2 rather than 3

myList[2]

which will return

'a'
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading