0% found this document useful (0 votes)
3 views21 pages

Python Part 4

This document provides an overview of data structures in Python, including lists, tuples, sets, and dictionaries. It explains their characteristics, methods, and practical examples for each type. By the end of this section, readers will be prepared to tackle real programming projects and advanced topics.

Uploaded by

satyamanand638
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views21 pages

Python Part 4

This document provides an overview of data structures in Python, including lists, tuples, sets, and dictionaries. It explains their characteristics, methods, and practical examples for each type. By the end of this section, readers will be prepared to tackle real programming projects and advanced topics.

Uploaded by

satyamanand638
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

---

🐍 PYTHON PROGRAMMING
📘 PART 4: DATA STRUCTURES
(LIST, TUPLE, SET, DICTIONARY
– FULL DETAIL)

> Is part ke baad tum real


programs, projects aur advanced
topics ke liye ready ho jaoge.

---
1️⃣ Data Structure kya hota hai?

📌 Simple words me:


Data ko organize karke store karne
ka tareeka = Data Structure

🧠 Real-life example:
School register (list of students)

Dictionary (word → meaning)

Bag me books alag-alag subjects


ki
---

2️⃣ Types of Data Structures in


Python

Python me mainly 4 built-in data


structures hote hain:

1️⃣ List
2️⃣ Tuple
3️⃣ Set
4️⃣ Dictionary
---

🔹 1. LIST (Most Important)


📌 List kya hoti hai?
Ordered collection of items

Changeable (mutable)

Index based

✍️ Create List:
marks = [85, 90, 78, 92]

---

🔹 Access List Elements


print(marks[0]) # 85
print(marks[-1]) # 92

👉 Index 0 se start hota hai


---

🔹 List me loop
for m in marks:
print(m)

---

🔹 List Methods (Very Important)


➕ append()
[Link](88)

➕ insert()
[Link](1, 95)
❌ remove()
[Link](78)

❌ pop()
[Link]()

🔄 sort()
[Link]()

🔄 reverse()
[Link]()
---

🔹 List Example Program


students = []

for i in range(3):
name = input("Enter name: ")
[Link](name)

print(students)

---
🔹 2. TUPLE
📌 Tuple kya hoti hai?
Ordered

Unchangeable (immutable)

Faster than list

✍️ Create Tuple:
t = (10, 20, 30)
❌ Change nahi kar sakte:
t[0] = 5 # Error

---

🔹 Tuple ka use kyun?


Fixed data

Security

Performance
---

🔹 3. SET
📌 Set kya hota hai?
Unordered

Unique values only

Duplicate allowed nahi

✍️ Create Set:
s = {1, 2, 3, 3, 4}
print(s)

Output:

{1, 2, 3, 4}

---

🔹 Set Methods
➕ add()
[Link](5)
❌ remove()
[Link](2)

🔄 union()
a = {1,2}
b = {3,4}
print([Link](b))

---

🔹 Set ka use:
Duplicate remove
Mathematical operations

---

🔹 4. DICTIONARY (Most
Powerful)

📌 Dictionary kya hoti hai?


Key : Value pairs

Unordered
Fast access

✍️ Create Dictionary:
student = {
"name": "Satyam",
"age": 15,
"class": 10
}

---

🔹 Access values
print(student["name"])

---

🔹 Dictionary Methods
➕ Add / Update
student["marks"] = 90

❌ Delete
del student["age"]

🔁 Loop
for key, value in [Link]():
print(key, value)

---

🔹 Dictionary Example Program


n = int(input("How many students?
"))
data = {}

for i in range(n):
name = input("Name: ")
marks = int(input("Marks: "))
data[name] = marks

print(data)

---

🔹 List vs Tuple vs Set vs


Dictionary

Feature​List​ Tuple​ Set​ Dict

Ordered​ Yes​ Yes​ No​ No


Mutable​Yes​ No​ Yes​ Yes
Duplicate​ Yes​ Yes​ No​ No
Indexed​Yes​ Yes​ No​ Keys
---

🧪 Practice Questions (Important)


1️⃣ List me even numbers store karo
2️⃣ Tuple me 5 subjects store karo
3️⃣ Set se duplicate remove karo
4️⃣ Dictionary se topper student find
karo
5️⃣ List of dictionaries banao
(advanced)
---

🎯 PART 4 RESULT
Ab tum:

Data ko efficiently store kar sakte


ho

Real-life problems solve kar sakte


ho

🔥
Advanced Python ke liye ready ho

You might also like