Python List Full Notes
Python List Full Notes
1. What is a List?
- A List is a built-in data structure in Python that is used to store multiple items in a single variable.
- Lists can store elements of different data types (integers, strings, floats, etc.).
2. Creating a List
Example:
numbers = [1, 2, 3, 4]
- Negative indexing starts from the end (-1 for last item).
fruits[0] # 'apple'
fruits[-1] # 'mango'
4. List Slicing
print(fruit)
7. Checking Existence
if 'apple' in fruits:
print('Yes')
8. List Length
len(fruits) # returns 3
fruits.append('grape')
fruits.insert(1, 'kiwi')
print(matrix[0][1]) # 2
new_list = old_list.copy()
list1.extend(list2)
17. Built-in Functions with Lists
- Lists are mutable: their contents can be changed using indexing or methods like append(),
remove(), etc.
- Use lists when you need an ordered collection that can change (add/remove/update elements).