🟢 Beginner  ·  Lesson 13

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.

💡 At a Glance
PointDetails
Course AreaCore Python
Basic programming concepts used to write Python programs.
Main Usestoring fixed records
Example Filetuples-sets.py
Practice FocusRun, 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.

TermMeaning
tupleOrdered immutable collection written with parentheses.
setUnordered collection that stores unique values.
immutableObject cannot be changed after creation.
uniqueDuplicate values are not stored.
membershipChecking 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.

Basic Pattern
coordinates = (25.4, 78.1)
subjects = {"Maths", "Science", "English", "Maths"}
print("Coordinates:", coordinates)
print("Subjects:", subjects)
print("Science" in subjects)

Complete Example Program

Python – tuples-sets.py
coordinates = (25.4, 78.1)
subjects = {"Maths", "Science", "English", "Maths"}

print("Coordinates:", coordinates)
print("Subjects:", subjects)
print("Science" in subjects)

Expected Output

Coordinates: (25.4, 78.1) Subjects: {'Science', 'English', 'Maths'} True

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

  1. Type the program in tuples-sets.py and run it.
  2. Change input values or sample data and observe the new output.
  3. Create one example related to storing fixed records.
  4. 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

TermMeaning
tupleOrdered immutable collection written with parentheses.
setUnordered collection that stores unique values.
immutableObject cannot be changed after creation.
uniqueDuplicate values are not stored.
membershipChecking 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 करें.

Basic Pattern
coordinates = (25.4, 78.1)
subjects = {"Maths", "Science", "English", "Maths"}
print("Coordinates:", coordinates)
print("Subjects:", subjects)
print("Science" in subjects)

Complete Example Program

Python – tuples-sets.py
coordinates = (25.4, 78.1)
subjects = {"Maths", "Science", "English", "Maths"}

print("Coordinates:", coordinates)
print("Subjects:", subjects)
print("Science" in subjects)

Expected Output

Coordinates: (25.4, 78.1) Subjects: {'Science', 'English', 'Maths'} True

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

  1. Program ko tuples-sets.py file me type karke run karein.
  2. Values change karke output compare karein.
  3. storing fixed records par ek छोटा example banayen.
  4. 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.

← Back to Python Tutorial