Get item at specific index in list
To get item from a list, at specific index, in Python, we can use square bracket notation on the list.
The syntax of the expression to get an item from list x
at index i
is
x[i]
Examples
1. Get item at index 4 in list x
In the following program, we take a list x
, get the value at index 4
, and print it to console output.
Python Program
x = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']
item = x[4]
print(item)
Run Output
e
Explanation
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']
0 1 2 3 4 5 6 7 <- indices
x[4] = 'e'
Summary
In this tutorial of Python Examples, we learned how to get an item from the list at specified index, with the help of well detailed examples.
Related Tutorials
- How to Get List of all Files in Directory and Sub-directories?
- Python – Check if Element is in List
- Python List – Add Item
- How to Reverse Python List?
- How to Insert Item at Specific Index in Python List?
- Shuffle Python List
- Python List without Last Element
- Python – Convert List to Dictionary
- Python List of Functions
- Python – Get Index or Position of Item in List