Learn and Learn

Learn And Learn - great place for tutorials, references and how-to

How to Get Item or Element From List in Python

To get items or elements from the Python list, you can use list index number. Remember that Python lists index always starts from 0. So, the first item of list is indexed at 0.

Index of the list in Python:

Index means the position of something. For example, you are standing at fifth position in the queue. Your index according to the queue is 5. If you are at the fifth position in a Python list. Your index according to Python list is 4 because Python list object starts from zero.

How Python index elements or items in the list

Let’s create a list in Python.
myList = [ 'aa','bb','cc','dd','ee','ff']
Index    Items

0        aa
1        bb
2        cc
3        dd
4        ee
5        ff


Now we get single item from list “myList”



How to get all items or elements form a list in Python

You can get all individual elements of a list by using for loop. Look at the following example.


# get all individual elements
# get all elements
['aa', 'bb', 'cc', 'dd', 'ee', 'ff']


LearnAndLearn.com © 2018 - All rights reserved