Python List, Tuple, and Dictionary – Exam Notes
1. Python List
A list is a collection of items. It is changeable and uses [ ].
Example:
numbers = [10, 20, 30]
fruits = ["apple", "banana"]
2. List Methods
append() – adds an item
[Link](4)
remove() – removes an item
[Link]("apple")
insert() – adds item at specific index
[Link](1, "orange")
pop() – removes last item
[Link]()
3. Python Tuple
A tuple is like a list but unchangeable. Uses ( ).
Example:
days = ("Mon", "Tue", "Wed")
4. Tuple Methods
count() – counts occurrences
[Link](2)
index() – returns position of value
[Link](3)
5. Dictionary
Stores data in key : value pairs using { }.
Example:
student = {"name": "Ahmad", "age": 20}
6. Dictionary Methods
get() – get a value
[Link]("age")
keys() – all keys
[Link]()
values() – all values
[Link]()
update() – update values
[Link]({"age": 21})
pop() – remove key
[Link]("age")