Python Collections Tutorial: List, Tuple, Set & Dictionary with Examples Beginner 2026
Python List vs Tuple vs Set vs Dictionary – Complete Guide with Examples
Python Collections (List, Tuple, Set & Dictionary)
Introduction
Python provides several built-in data structures known as collections,
which help programmers store, organize, and manage multiple values efficiently.
Collections are one of the most important concepts in Python because almost
every real-world program uses them.Instead of storing one value at a time, collections allow you to store multiple values inside a single variable. Python offers four primary collection data types:
- List
- Tuple
- Set
- Dictionary
Python collections flowchart
│
┌────────────────┼─────────────┐
Sequence Unique Data Key-Value Data
│ │ │
┌─ ─┴─┐ │ │
│ | │ │
List Tuple Set Dictionary
Ordered Ordered Unordered Key : Value
Mutable Immutable Unique Mutable
Duplicates Duplicates No Duplicates Fast Search
A List is one of the most commonly used collection types in Python. It stores multiple values in a single variable.
A list is ordered, changeable (mutable), and allows duplicate values.
Think of it like a shopping list written on paper. You can add new items, remove items, or change existing items whenever you want.
Syntax
fruits = ["Apple", "Banana", "Mango"]students = ["Rahul", "Priya", "Amit"]
Output
['Rahul', 'Priya', 'Amit']
List Indexing
Each element has an index.fruits = ["Apple", "Banana", "Mango"]
print(fruits[1])
print(fruits[-1])
Output
AppleBanana
Mango
List Slicing
numbers = [10,20,30,40,50]
Output
[20,30,40]
List Methods
append()fruits.append("Orange")
insert()
fruits.insert(1,"Kiwi")
remove()
fruits.remove("Banana")
pop()
fruits.pop()
sort()
numbers.sort()
reverse()
numbers.reverse()
count()
numbers.count(20)
index()
numbers.index(30)
List Features
- Ordered
- Mutable
- Allows duplicates
- Supports indexing
- Supports slicing
- Can store different data types
List Advantages
✔ Easy to modify✔ Ordered
✔ Supports indexing
✔ Can store multiple data types
✔ Many built-in methods
List Disadvantages
- Uses more memory
- Slower searching compared to dictionary
- Duplicate values may create confusion
List Flowchart
Create List│
▼
Store Multiple Items
│
▼
Access using Index
│
▼
Modify / Add / Remove
│
▼
Display Result
2. What is a Tuple?
DefinitionA Tuple is similar to a list but cannot be changed after creation.
It is ordered, immutable, and allows duplicate values.
Imagine printing your exam marks on an official certificate. Once printed, they cannot be changed.
Tuple works similarly.
Syntax
marks = (80, 85, 90)Example1
marks = (78, 89, 92)
Output
(78, 89, 92)Create Tuple
student = ("Rahul",22,"Python")print(student)
Output
('Rahul',22,'Python')
Tuple Unpacking
name, age, country = personprint(age)
print(country)
Output
John
25
India
Features
- Ordered
- Immutable
- Allows duplicates
- Faster than list
- Supports indexing
Uses of Tuple
Tuple is useful when data should never change.Examples
- Date of Birth
- Coordinates
- Employee ID
- RGB Colors
- Fixed settings
Tuple Advantages
✔ Faster✔ Less memory
✔ Data safety
✔ Hashable
Tuple Disadvantages
- Cannot modify data
- Cannot add new values
- Cannot delete individual items
Tuple Flowchart
Create Tuple│
▼
Store Fixed Data
│
▼
Read Values
│
▼
Cannot Modify
3. What is a Set?
DefinitionA Set stores only unique values.
It automatically removes duplicate values.
A set is unordered, mutable, and does not support indexing.
Imagine a classroom attendance register where each student's name should appear only once.
Syntax
numbers = {10,20,30}Example 1
numbers = {10,20,30,20,10}
Output
{10,20,30}
Set Methods
add()
numbers.add(50)
remove()
numbers.remove(20)
discard()
numbers.discard(30)
clear()
numbers.clear()
Union
A = {1,2,3}B = {3,4,5}
Output
{1,2,3,4,5}Intersection
print(A & B)
Output
{3}
Difference
print(A - B)Output
{1,2}
Symmetric Difference
print(A ^ B)
Output
{1,2,4,5}
Set Features
- Unordered
- Mutable
- Unique values only
- Fast searching
- Mathematical operations
Set Advantages
✔ Very fast✔ Removes duplicates
✔ Supports Union
✔ Supports Intersection
Uses of Set
- Remove duplicates
- Unique visitors
- Unique email IDs
- Student roll numbers
- Mathematical operations
Set Disadvantages
- No indexing
- Unordered
- Cannot access by position
│
▼
Insert Values
│
▼
Remove Duplicate Values
│
▼
Store Unique Items
4. What is a Dictionary?
DefinitionA Dictionary stores data as Key : Value pairs.
Instead of remembering positions, you remember keys.
Think about a student ID card.
Roll Number → 101
This is exactly how a dictionary works
student = {
"name":"Rahul",
"age":20
}
Dictionary Example
student = {"Name":"Rahul",
"Age":20,
"Course":"Python"
}
dictionary Output
{'Name': 'Rahul', 'Age': 20, 'Course': 'Python'}
Dictionary Features
- Key-Value pair
- Mutable
- Fast lookup
- Unique keys
- Values can repeat
Keys
print(student.keys())Output
Values
print(student.values())Output
dict_values(['Rahul',22,'Python'])
Items
print(student.items())Output
dict_items([('name','Rahul'),('age',22),('course','Python')])
Dictionary Methods
get()student.get("name")
update()
student.update({"city":"Mumbai"})
pop()
student.pop("age")
clear()
student.clear()
- Student records
- Employee information
- Product details
- API responses
- Database records
- User profiles
Dictionary Advantages
✔ Extremely fast lookup✔ Easy to organize
✔ Flexible
✔ Supports nested data
Dictionary Disadvantages
- Keys must be unique
- Uses more memory
- No positional indexing
Dictionary Flowchart
Create Dictionary│
▼
Store Key : Value
│
▼
Access Using Key
│
▼
Update/Delete/Add
|
Feature |
List |
Tuple |
Set |
Dictionary |
|
Ordered |
Yes |
Yes |
No |
Yes |
|
Mutable |
Yes |
No |
Yes |
Yes |
|
Duplicate Values |
Yes |
Yes |
No |
Keys No |
|
Indexing |
Yes |
Yes |
No |
By Key |
|
Faster |
Medium |
Fast |
Fast |
Fast |
Frequently Asked Questions
(FAQs)
1. What is the difference
between List and Tuple?A list is mutable, meaning you can add, remove, or change elements. A tuple is immutable, so once it is created, its contents cannot be changed.
Use a tuple when the data should remain constant, such as dates of birth, geographic coordinates, or configuration values.
3. Why does a Set remove duplicate values?
A set is designed to store only unique elements, making it useful for eliminating duplicates automatically.
4. Can a Set contain duplicate values?
No. Any duplicate values added to a set are ignored.
5. What is a Dictionary in Python?
A dictionary stores information as key-value pairs, allowing quick access to values using unique keys.
6. Which collection is the fastest for searching?
A dictionary is generally the fastest for looking up values by key. Sets are also very efficient for checking whether a value exists.
7. Can a List store different data types?
Yes. A list can contain strings, numbers, booleans, and even other lists or dictionaries.
8. Can Dictionary keys be duplicated?
No. Dictionary keys must be unique. If the same key is used again, the previous value is replaced.
9. Which collection is best for removing duplicates?
A set is the best choice because it automatically keeps only unique values.
10. Which collection should beginners learn first?
Start with lists, then learn tuples, sets, and dictionaries to understand the strengths of each.
Python Collections Interview Questions
- What are Python collections?
- What is the difference between a List and a Tuple?
- What is the difference between a Set and a List?
- Why are Sets unordered?
- What are Dictionary keys?
- Can a List contain another List?
- Why are Tuples immutable?
- What happens if duplicate keys are used in a Dictionary?
- Which collection uses key-value pairs?
- Which collection is best for unique values?
Conclusion
Python Collections are fundamental building blocks of Python programming. Lists are ideal for storing ordered and mutable data, Tuples are best for fixed data, Sets efficiently manage unique elements, and Dictionaries provide fast key-value access. Mastering these collection types will help you write cleaner, more efficient, and scalable Python applications.
Comments
Post a Comment