Python List, Tuple, and Dictionary (Easy to
Understand)
1. List
Definition
A List is a collection of items that can be changed
(mutable). It is written using square brackets [ ].
Real-Time Example
Think of a shopping bag. You can add or remove items
anytime.
🛒 Shopping Bag:
Rice
Milk
Bread
You can add Eggs or remove Milk whenever you want.
Syntax
fruits = ["Apple", "Banana", "Mango"]
print(fruits)
Output
['Apple', 'Banana', 'Mango']
Access Elements
fruits = ["Apple", "Banana", "Mango"]
print(fruits[0]) # Apple
print(fruits[1]) # Banana
Change Value
fruits = ["Apple", "Banana", "Mango"]
fruits[1] = "Orange"
print(fruits)
Output
['Apple', 'Orange', 'Mango']
Add Item
[Link]("Grapes")
print(fruits)
Remove Item
[Link]("Apple")
print(fruits)
1. LIST METHODS
fruits = ["Apple", "Banana", "Mango"]
1. append()
Definition: Adds one item at the end of the list.
fruits = ["Apple", "Banana"]
[Link]("Orange")
print(fruits)
Output
['Apple', 'Banana', 'Orange']
2. extend()
Definition: Adds multiple items to the list.
fruits = ["Apple", "Banana"]
[Link](["Mango", "Grapes"])
print(fruits)
Output
['Apple', 'Banana', 'Mango', 'Grapes']
3. insert()
Definition: Inserts an item at a specific position.
fruits = ["Apple", "Banana"]
[Link](1, "Orange")
print(fruits)
Output
['Apple', 'Orange', 'Banana']
4. remove()
Definition: Removes a specific item.
fruits = ["Apple", "Banana", "Orange"]
[Link]("Banana")
print(fruits)
Output
['Apple', 'Orange']
5. pop()
Definition: Removes an item by index.
fruits = ["Apple", "Banana", "Orange"]
[Link](1)
print(fruits)
Output
['Apple', 'Orange']
Remove last item:
[Link]()
6. clear()
Definition: Removes all items.
fruits = ["Apple", "Banana"]
[Link]()
print(fruits)
Output
[]
7. index()
Definition: Returns the position of an item.
fruits = ["Apple", "Banana", "Orange"]
print([Link]("Banana"))
Output
1
8. count()
Definition: Counts how many times an item appears.
numbers = [10,20,30,20,40,20]
print([Link](20))
Output
3
9. sort()
Definition: Sorts the list in ascending order.
numbers = [50,20,10,40]
[Link]()
print(numbers)
Output
[10,20,40,50]
Descending:
[Link](reverse=True)
10. reverse()
Definition: Reverses the list.
numbers = [10,20,30]
[Link]()
print(numbers)
Output
[30,20,10]
11. copy()
Definition: Creates a copy of the list.
list1 = [10,20,30]
list2 = [Link]()
print(list2)
Output
[10,20,30]
LIST METHODS SUMMARY
Method Purpose
append() Add one item
extend() Add multiple items
insert() Insert at position
remove() Remove by value
pop() Remove by index
clear() Remove all
index() Find position
count() Count items
sort() Sort list
reverse() Reverse list
copy() Copy list
2. Tuple
Definition
A Tuple is a collection of items that cannot be changed
(immutable). It is written using parentheses ( ).
Real-Time Example
Think of your Date of Birth.
📅 Date of Birth:
26-04-2001
You cannot change your birth date, so Tuple is perfect
for storing fixed data.
Syntax
colors = ("Red", "Green", "Blue")
print(colors)
Output
('Red', 'Green', 'Blue')
Access Elements
print(colors[0])
Output
Red
Not Allowed
colors[1] = "Yellow"
Output
TypeError
Because a Tuple cannot be modified.
2. TUPLE METHODS
numbers = (10,20,30,20,40)
Tuple has only 2 methods because it cannot be modified.
1. count()
numbers = (10,20,30,20,40)
print([Link](20))
Output
2
2. index()
numbers = (10,20,30,20,40)
print([Link](30))
Output
2
TUPLE METHODS SUMMARY
Method Purpose
count() Count occurrences
index() Find index
3. Dictionary
Definition
A Dictionary stores data in key-value pairs. It is written
using curly braces { }.
Real-Time Example
Think of a Student ID Card.
Key Value
Name Kavya
Age 25
Branch CSE
College Sridevi College
Each piece of information has a key and a value.
Syntax
student = {
"name": "Kavya",
"age": 25,
"branch": "CSE"
}
print(student)
Output
{'name': 'Kavya', 'age': 25, 'branch': 'CSE'}
Access Values
print(student["name"])
print(student["age"])
Output
Kavya
25
Add New Data
student["city"] = "Hyderabad"
print(student)
Update Data
student["age"] = 26
print(student)
3. DICTIONARY METHODS
student = {
"name":"Kavya",
"age":25,
"course":"Python"
}
1. get()
Definition: Returns value using key.
print([Link]("name"))
Output
Kavya
2. keys()
print([Link]())
Output
dict_keys(['name','age','course'])
3. values()
print([Link]())
Output
dict_values(['Kavya',25,'Python'])
4. items()
print([Link]())
Output
dict_items([('name','Kavya'),
('age',25),
('course','Python')])
5. update()
[Link]({"age":26})
print(student)
Output
{'name':'Kavya',
'age':26,
'course':'Python'}
6. pop()
[Link]("age")
print(student)
Output
{'name':'Kavya',
'course':'Python'}
7. popitem()
Removes the last inserted key-value pair.
student = {
"name":"Kavya",
"age":25,
"course":"Python"
}
[Link]()
print(student)
Output
{'name':'Kavya',
'age':25}
8. clear()
[Link]()
print(student)
Output
{}
9. copy()
student = {
"name":"Kavya",
"age":25
}
new_student = [Link]()
print(new_student)
Output
{'name':'Kavya',
'age':25}
10. setdefault()
Returns the value of a key. If the key does not exist, it
adds the key with the given default value.
student = {
"name":"Kavya"
}
[Link]("age",25)
print(student)
Output
{'name':'Kavya',
'age':25}
11. fromkeys()
Creates a new dictionary using given keys and the same
value.
keys = ["name","age","course"]
student = [Link](keys,"Not Available")
print(student)
Output
{'name':'Not Available',
'age':'Not Available',
'course':'Not Available'}
DICTIONARY METHODS SUMMARY
Method Purpose
get() Get value by key
keys() Get all keys
values() Get all values
items() Get key-value pairs
update() Update dictionary
pop() Remove by key
popitem() Remove last key-value pair
clear() Remove all items
copy() Copy dictionary
setdefault() Add key if missing
Method Purpose
fromkeys() Create dictionary from keys
Real-Time Comparison
Data Type Real-Time Example Can Change? Symbol
List Shopping Bag ✅ Yes []
Tuple Date of Birth ❌ No ()
Dictionary Student ID Card ✅ Yes {}
Complete Example
# List
subjects = ["Python", "Java", "C"]
# Tuple
days = ("Monday", "Tuesday", "Wednesday")
# Dictionary
student = {
"name": "Kavya",
"age": 25,
"course": "Python"
}
print(subjects)
print(days)
print(student)
Output
['Python', 'Java', 'C']
('Monday', 'Tuesday', 'Wednesday')
{'name': 'Kavya', 'age': 25, 'course': 'Python'}