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?
>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'