Advertisement
sissou123

Untitled

Mar 16th, 2022
1,119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.87 KB | None | 0 0
  1. How to Access Items in a List in Python
  2. In this section, we'll talk about accessing data stored in a list using their index.
  3.  
  4. Here is what a list looks like:
  5.  
  6. myList = ["yes", "no", "maybe"]
  7. The items are nested in square brackets where each item is separated by a comma.
  8.  
  9. Items in a list have index numbers assigned to them when the list is created or as we add them to the list. This index number starts at zero. So the first item in a list has an index number of zero and the second has an index number of one and so on.
  10.  
  11. In the list we created in the example above, the index of "yes" is 0, the index of "no" is 1, and the index of "maybe" is 2.
  12.  
  13. myList = ["yes", "no", "maybe"]
  14.  
  15. print(myList[0]) # yes
  16. print(myList[1]) # no
  17. print(myList[2]) # maybe
  18. Now let's look at some of the methods we can use to select the last item in our lists.
  19. for more:https://usdshort.com/TDoB5
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement