A list is an ordered, mutable (changeable) collection of items.
It can store different data types — integers, strings, floats, even other lists!

✅ Example:
fruits = ["apple", "banana", "cherry"]
numbers = [10, 20, 30, 40]
mixed = [10, "Sakshi", 3.5, True]
✅ Various ways:
list1 = [] # empty list
list2 = list((1, 2, 3)) # from tuple
list3 = ["Python", "Java", "C++"]
Lists use zero-based indexing.
✅ Example:
fruits = ["apple", "banana", "cherry"]
print(fruits[0]) # apple
print(fruits[-1]) # cherry
✅ Example:
nums = [10, 20, 30, 40, 50]
print(nums[1:4]) # [20, 30, 40]
print(nums[:3]) # [10, 20, 30]
print(nums[::-1]) # [50, 40, 30, 20, 10]
✅ Example:
fruits = ["apple", "banana", "cherry"]
fruits[1] = "mango"
print(fruits) # ['apple', 'mango', 'cherry']
| Method | Description | Example |
|---|---|---|
| append() | Add single element at end | fruits.append("grape") |
| insert(index, item) | Insert at specific position | fruits.insert(1, "orange") |
| extend() | Add multiple items | fruits.extend(["kiwi", "melon"]) |
✅ Example:
numbers = [1, 2, 3]
numbers.append(4)
numbers.insert(1, 10)
numbers.extend([5, 6])
print(numbers) # [1, 10, 2, 3, 4, 5, 6]
| Method | Description | Example |
|---|---|---|
| remove(value) | Removes first occurrence | fruits.remove("apple") |
| pop(index) | Removes and returns item | fruits.pop(2) |
| clear() | Empties the list | fruits.clear() |
| del | Delete using index or entire list | del fruits[0] |
✅ Example:
nums = [10, 20, 30, 40]
nums.pop(2) # removes 30
nums.remove(10) # removes 10
print(nums) # [20, 40]
✅ Example:
colors = ["red", "green", "blue"]
for c in colors:
print(c)
✅ Example:
names = ["Sakshi", "Riya", "Aman"]
if "Sakshi" in names:
print("Found!")
| Function | Description | Example |
|---|---|---|
| len() | Length of list | len(nums) |
| min() | Minimum value | min(nums) |
| max() | Maximum value | max(nums) |
| sum() | Sum of all elements | sum(nums) |
| sorted() | Returns sorted list | sorted(nums) |
✅ Example:
nums = [5, 2, 9, 1]
print(len(nums)) # 4
print(sum(nums)) # 17
print(sorted(nums)) # [1, 2, 5, 9]

| Method | Description |
|---|---|
| count(x) | Counts occurrences of x |
| index(x) | Returns index of x |
| reverse() | Reverses list |
| sort() | Sorts list (ascending by default) |
| copy() | Copies list |
✅ Example:
nums = [3, 1, 4, 2]
nums.sort()
nums.reverse()
print(nums) # [4, 3, 2, 1]
✅ Example:
matrix = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
print(matrix[1][2]) # 6
✅ Example:
squares = [x**2 for x in range(1, 6)]
print(squares) # [1, 4, 9, 16, 25]
✅ With condition:
even = [x for x in range(10) if x % 2 == 0]
print(even) # [0, 2, 4, 6, 8]