Tuples and Sets in Python
Python Tuples और Sets
What are Tuples and Sets?
Tuples and Sets means tuples are ordered and immutable, while sets are unordered collections of unique values.
In real programs, this topic helps in storing fixed records. Learn the idea first, then type the program yourself and compare the output.
| Point | Details |
|---|---|
| Course Area | Core Python Basic programming concepts used to write Python programs. |
| Main Use | storing fixed records |
| Example File | tuples-sets.py |
| Practice Focus | Run, change values, and explain the output line by line. |
Why should you learn this?
- It is useful for storing fixed records.
- It connects with removing duplicate values.
- It improves your ability to read, write and debug Python programs.
Important Terms
These terms are used directly in this lesson. Understand them before memorising the code.
| Term | Meaning |
|---|---|
| tuple | Ordered immutable collection written with parentheses. |
| set | Unordered collection that stores unique values. |
| immutable | Object cannot be changed after creation. |
| unique | Duplicate values are not stored. |
| membership | Checking if a value exists inside a sequence using in or not in. |
Syntax / Basic Pattern
The simple pattern is: prepare data, apply the concept, then show the result.
coordinates = (25.4, 78.1)
subjects = {"Maths", "Science", "English", "Maths"}
print("Coordinates:", coordinates)
print("Subjects:", subjects)
print("Science" in subjects)Complete Example Program
coordinates = (25.4, 78.1)
subjects = {"Maths", "Science", "English", "Maths"}
print("Coordinates:", coordinates)
print("Subjects:", subjects)
print("Science" in subjects)Expected Output
Program Explanation
coordinates = (25.4, 78.1)stores a value in coordinates.subjects = {"Maths", "Science", "English", "Maths"}stores a value in subjects.print("Coordinates:", coordinates)displays information or calculated result on the screen.print("Subjects:", subjects)displays information or calculated result on the screen.print("Science" in subjects)displays information or calculated result on the screen.
Where will you use it?
- Storing fixed records.
- Removing duplicate values.
- Fast membership checking.
Common Mistakes
- Writing code with wrong indentation.
- Using input() value directly in calculations without converting it to int or float.
- Using unclear variable names that make the program difficult to understand.
Practice Tasks
- Type the program in
tuples-sets.pyand run it. - Change input values or sample data and observe the new output.
- Create one example related to storing fixed records.
- Write 5 lines explaining the logic in your own words.
Summary
Tuples and Sets is not a theory-only topic. You should be able to explain the meaning, write the example, run it successfully, and use it in a small practical program.
Tuples और Sets क्या है?
Tuples और Sets ka matlab hai: Tuples are ordered and immutable, while sets are unordered collections of unique values. Simple words me, ye topic practical Python programs likhne me direct use hota hai.
Is topic ko sirf definition ke liye nahi, balki storing fixed records jaise real examples ke liye practice karein.
यह क्यों सीखना जरूरी है?
- Ye storing fixed records me kaam aata hai.
- Ye removing duplicate values se bhi connected hai.
- Isse aap code ka output aur errors better samajh paate hain.
Important Terms
| Term | Meaning |
|---|---|
| tuple | Ordered immutable collection written with parentheses. |
| set | Unordered collection that stores unique values. |
| immutable | Object cannot be changed after creation. |
| unique | Duplicate values are not stored. |
| membership | Checking if a value exists inside a sequence using in or not in. |
Syntax / Basic Pattern
Basic idea: pehle data तैयार करें, phir Python logic apply करें, aur finally result display करें.
coordinates = (25.4, 78.1)
subjects = {"Maths", "Science", "English", "Maths"}
print("Coordinates:", coordinates)
print("Subjects:", subjects)
print("Science" in subjects)Complete Example Program
coordinates = (25.4, 78.1)
subjects = {"Maths", "Science", "English", "Maths"}
print("Coordinates:", coordinates)
print("Subjects:", subjects)
print("Science" in subjects)Expected Output
Program Explanation
coordinates = (25.4, 78.1)stores a value in coordinates.subjects = {"Maths", "Science", "English", "Maths"}stores a value in subjects.print("Coordinates:", coordinates)displays information or calculated result on the screen.print("Subjects:", subjects)displays information or calculated result on the screen.print("Science" in subjects)displays information or calculated result on the screen.
Practical Uses
- Storing fixed records.
- Removing duplicate values.
- Fast membership checking.
Common Mistakes
- Writing code with wrong indentation.
- Using input() value directly in calculations without converting it to int or float.
- Using unclear variable names that make the program difficult to understand.
Practice Tasks
- Program ko
tuples-sets.pyfile me type karke run karein. - Values change karke output compare karein.
- storing fixed records par ek छोटा example banayen.
- Logic ko apne words me 5 lines me likhein.
सारांश
Tuples and Sets ko tab complete maanenge jab aap iska meaning, example, output aur practical use clearly explain kar saken.