Introduction to Lists :
A Python list is a built-in, ordered, and mutable collection data type used to store multiple items in a single variable. These items can be of any data type, including integers, strings, booleans, and even other lists. The values are stored inside square brackets " [ ] ".
Example :
Why Lists are Used ?
- Data Handling
- Tables & Records
- Menu systems
- Real-world applications
Features of Lists :
Ordered - meaning the order remains the same until changed
Mutable - meaning one can change , update or replace list items
Allow Duplicates - meaning list can store repeated values
Allow Multiple Data Types - meaning same list can store different kind of values
Dynamic - meaning items can be added , removed or modified
Supports Indexing and Slicing
Accessing List Items in Python :
Each item in a list has a position called an index. Indexing starts from 0.
| Value | 10 | 20 | 30 | 40 | 50 |
|---|---|---|---|---|---|
| Forward Index | 0 | 1 | 2 | 3 | 4 |
| Negative Index | -5 | -4 | -3 | -2 | -1 |
Access Item by Index :
Access a range of Items :
Access Item thorugh Loops