
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Accessing Values of Lists in Python
To access values in lists, use the square brackets for slicing along with the index or indices to obtain value available at that index.
Example
#!/usr/bin/python list1 = ['physics', 'chemistry', 1997, 2000]; list2 = [1, 2, 3, 4, 5, 6, 7 ]; print "list1[0]: ", list1[0] print "list2[1:5]: ", list2[1:5]
Output
When the above code is executed, it produces the following result −
list1[0]: physics list2[1:5]: [2, 3, 4, 5]
- Related Articles
- Accessing Values of Strings in Python
- Accessing Values of Tuples in Python
- Accessing Values of Dictionary in Python
- Safely Accessing Deeply Nested Values In JavaScript
- Python program to find missing and additional values in two lists?
- Accessing Attributes and Methods in Python
- Unpacking tuple of lists in Python
- Accessing Key-value in a Python Dictionary
- Updating Lists in Python
- Intersection of Two Linked Lists in Python
- Python - Intersection of multiple lists
- Accessing index and value in a Python list
- Accessing nth element from Python tuples in list
- Custom Multiplication in list of lists in Python
- Multi-dimensional lists in Python

Advertisements