Seedha content par jao
🤖 Python Hindi Bot
Namaste! Main Python Hindi Bot hoon 🐍
Python ya AI se related kuch bhi type karke pucho, ya neeche se quick sawaal chuno.
WhatsApp

Stay Connected with PythonHindii

Join our WhatsApp Community to get the latest Python tutorials, coding tips, interview questions, project updates, and learning resources directly on your phone.

Join WhatsApp Community
⇧
Python Hindi Logo
Python in Hindi | Programming Education
Python programming tutorial in Hindi banner Python code learning illustration Hindi Python student coding illustration Python data code pattern background

Python Tutorial in HindiiLearn Python Programming for Free

Learn Python from Beginner to Advanced in simple Hindi.

print("Namaste Python!")
# Variable banana
naam = "Ankit"
umar = 25
 
for i in range(3):
  print("Sikho!")
 
# Output:
Sikho! Sikho! Sikho!

Why Students Learn Here

📚

Structured Tutorials

Beginner se Advanced tak step-by-step organized lessons.

💻

Practical Code

Real examples aur hands-on code jo actually samajh aaye.

🧠

Python + AI Path

Ek clear roadmap jo Python se AI tak le jaata hai.

🚀

Projects & Career

Portfolio-ready projects aur interview preparation.

Ye Kaise Kaam Karta Hai

Hindi mein Python, AI aur Data Skills seekhne ka sabse simple tareeka.

📘

Seekhein

Beginner se Advanced tak, best curated tutorials aur guides Hindi mein.

💻

Practice Karein

Real code examples aur mini-projects ke through hands-on practice karein.

💬

Judein

WhatsApp community se judkar apne doubts clear karein, akele nahi seekhenge.

Python to AI Learning Roadmap

Step-by-step learning path from Python basics to AI, Data Science and career-ready projects.

1
🐍

Python Basics

Introduction, Variables, Data Types, Operators, Input & Output, Conditions, Loops, Functions

Start Python →
2
💻

Python Intermediate

Lists, Tuples, Sets, Dictionaries, Strings, Functions, Modules, File Handling, Exception Handling

Continue Python →
3
⚙️

Advanced Python

OOP, Iterators, Generators, Decorators, Regular Expressions, APIs, Automation, Virtual Environments

Learn Advanced Python →
4
🗄️

SQL & Databases

SQL Basics, MySQL, SELECT, INSERT, UPDATE, DELETE, JOIN, GROUP BY, Database Projects

Learn SQL →
5
📊

Data Analytics

NumPy, Pandas, Data Cleaning, Data Visualization, Matplotlib, Exploratory Data Analysis

Learn Data Analytics →
6
🤖

Machine Learning

ML Basics, Supervised & Unsupervised Learning, Regression, Classification, Model Evaluation, Scikit-learn

Learn Machine Learning →
7
🧠

Artificial Intelligence

AI Fundamentals, Generative AI, AI Tools, Prompt Engineering, LLM Concepts, AI Automation

Explore AI →
8
🚀

Projects & Career

Python Projects, AI Projects, Data Projects, Portfolio, GitHub, Interview Preparation, Career Roadmap

Build Your Career →

Python में Set क्या होता है? Python Set Methods & Practical Examples (2026)

Python Set in Hindi - Complete Python Course 2026

Python Set

List और Tuple में हमने देखा कि values को एक क्रम (order) में और index के जरिए रखा जाता है। Python में एक और data structure है — Set — जो सिर्फ unique values रखता है और उसमें कोई index नहीं होता।

अगर आपने अभी List या Tuple नहीं पढ़ा है, तो पहले Python Lists Complete Guide in Hindi और Python Tuple in Hindi पढ़ना उपयोगी रहेगा, क्योंकि Set को समझने के लिए इन दोनों से comparison करना आसान होता है। Examples खुद run करने के लिए हमारा Online Python Editor & Compiler use कर सकते हैं।

🎥 Video में पूरा Topic समझें

Python Set क्या है?

Set Python का एक data structure है, जिसमें values को { } curly brackets में रखा जाता है, लेकिन इसमें कोई duplicate value नहीं रह सकती और values का कोई fixed order भी नहीं होता।

सरल भाषा में — Set एक ऐसा container है जो सिर्फ unique values रखता है, बिना किसी क्रम के।
Example
fruits = {"apple", "banana", "mango"} print(fruits)

Output:

{'banana', 'apple', 'mango'}

ध्यान दें — output का order हर बार अलग हो सकता है, क्योंकि Set में elements का कोई fixed क्रम नहीं होता।

Try it Yourself »

Set Create करना

Set बनाने के लिए values को curly brackets { } के अंदर, comma से अलग करके लिखा जाता है।

Syntax
set_name = {value1, value2, value3}
Example
numbers = {10, 20, 30, 40} print(numbers)

Output:

{40, 10, 20, 30}
Try it Yourself »

Unique और Duplicate Values

Set की सबसे बड़ी पहचान यही है — अगर कोई value दो बार दी जाए, तो Set खुद-ब-खुद उसकी सिर्फ एक copy रखता है।

Example
numbers = {1, 2, 2, 3, 3, 3, 4} print(numbers)

Output:

{1, 2, 3, 4}

Duplicate values (2 और 3) अपने आप हट गईं और सिर्फ unique values बचीं।

Try it Yourself »

Different Data Types Store करना

Set में भी अलग-अलग data types की values एक साथ रखी जा सकती हैं।

Example
mixed_set = {"Ankit", 25, True, 5.5} print(mixed_set)

Output:

{'Ankit', True, 25, 5.5}
Try it Yourself »

Empty Set और set()

एक empty set बनाने के लिए सिर्फ { } लिखना काफी नहीं है, क्योंकि Python उसे empty dictionary समझ लेता है। इसके लिए set() function इस्तेमाल किया जाता है।

❌ गलत — यह Set नहीं बनेगा
empty = {} print(type(empty))

Output:

<class 'dict'>
✅ सही — set() के साथ
empty = set() print(type(empty))

Output:

<class 'set'>
Try it Yourself »

Set में Indexing क्यों नहीं होती?

List और Tuple में हर element की एक fixed position (index) होती है, लेकिन Set में elements का कोई तय क्रम ही नहीं होता — इसलिए Set में indexing possible नहीं है।

Example — यह error देगा
fruits = {"apple", "banana", "mango"} print(fruits[0]) # TypeError

Output:

TypeError: 'set' object is not subscriptable
Note: Set के elements को access करने के लिए index की जगह for loop या in keyword इस्तेमाल किया जाता है।

add() से Value Add करना

add() से Set में एक नई value जोड़ी जा सकती है।

Example
fruits = {"apple", "banana"} fruits.add("mango") print(fruits)

Output:

{'banana', 'apple', 'mango'}
Try it Yourself »

remove() और discard()

दोनों methods Set से कोई value हटाते हैं, लेकिन इनमें एक जरूरी फर्क है — अगर value मौजूद न हो, तो remove() error देता है, जबकि discard() चुपचाप कुछ नहीं करता।

remove() — value न होने पर Error
fruits = {"apple", "banana"} fruits.remove("mango") # KeyError
discard() — value न होने पर भी कोई Error नहीं
fruits = {"apple", "banana"} fruits.discard("mango") # कोई error नहीं print(fruits)

Output:

{'apple', 'banana'}
Try it Yourself »

pop() का Basic Use

Set पर pop() इस्तेमाल करने पर वह किसी भी एक random element को हटाकर return करता है, क्योंकि Set में कोई fixed order नहीं होता।

Example
fruits = {"apple", "banana", "mango"} removed = fruits.pop() print(fruits) print("Removed:", removed)

Output (example):

{'banana', 'mango'} Removed: apple

यह हमेशा वही element नहीं होगा — Set में order fixed न होने की वजह से pop() कोई भी element हटा सकता है।

Try it Yourself »
Methodकाम
add(value)Set में नई value जोड़ता है
remove(value)Value हटाता है, न मिलने पर error देता है
discard(value)Value हटाता है, न मिलने पर error नहीं देता
pop()कोई भी एक random element हटाकर return करता है

len() से Set की Length निकालना

Example
fruits = {"apple", "banana", "mango"} print(len(fruits))

Output:

3
Try it Yourself »

in से Element Check करना

Example
fruits = {"apple", "banana", "mango"} print("banana" in fruits) print("grapes" in fruits)

Output:

True False
Try it Yourself »

union()

union() दो sets के सारे unique elements को मिलाकर एक नया set बनाता है।

Example
a = {1, 2, 3} b = {3, 4, 5} result = a.union(b) print(result)

Output:

{1, 2, 3, 4, 5}

Common value (3) सिर्फ एक बार आई, क्योंकि Set में duplicates नहीं रहते।

Try it Yourself »

intersection()

intersection() सिर्फ वही elements return करता है जो दोनों sets में common हों।

Example
a = {1, 2, 3} b = {2, 3, 4} result = a.intersection(b) print(result)

Output:

{2, 3}
Try it Yourself »

difference()

difference() वह elements return करता है जो पहले set में हैं, लेकिन दूसरे set में नहीं।

Example
a = {1, 2, 3} b = {2, 3, 4} result = a.difference(b) print(result)

Output:

{1}

1 सिर्फ a में है, b में नहीं — इसलिए वही return हुआ।

Try it Yourself »
MethodResult
union()दोनों sets के सारे unique elements
intersection()दोनों sets में common elements
difference()पहले set में मौजूद, दूसरे में नहीं

clear()

clear() Set के सारे elements को हटाकर उसे खाली कर देता है।

Example
fruits = {"apple", "banana", "mango"} fruits.clear() print(fruits)

Output:

set()
Try it Yourself »

Set और List में Basic Difference

FeatureListSet
Brackets[ ]{ }
OrderFixed order रहता हैकोई fixed order नहीं
Duplicate Valuesअनुमति हैअनुमति नहीं, अपने आप हट जाती हैं
Indexingसंभव हैसंभव नहीं
Mutableहाँहाँ (लेकिन elements खुद immutable होने चाहिए)

Practical Example — Duplicate Names हटाना

Example
student_list = ["Ankit", "Rahul", "Priya", "Ankit", "Rahul"] unique_students = set(student_list) print("With Duplicates:", student_list) print("Without Duplicates:", unique_students) print("Total Unique Students:", len(unique_students))

Output:

With Duplicates: ['Ankit', 'Rahul', 'Priya', 'Ankit', 'Rahul'] Without Duplicates: {'Priya', 'Ankit', 'Rahul'} Total Unique Students: 3

यह Set का सबसे common real-world इस्तेमाल है — किसी list में से duplicate values को आसानी से हटाना।

Try it Yourself »

Practical Example — Common Subjects निकालना

Example
student_a = {"Math", "Science", "English"} student_b = {"Science", "English", "History"} common_subjects = student_a.intersection(student_b) all_subjects = student_a.union(student_b) only_a = student_a.difference(student_b) print("Common:", common_subjects) print("All Subjects:", all_subjects) print("Only Student A:", only_a)

Output:

Common: {'Science', 'English'} All Subjects: {'Math', 'Science', 'English', 'History'} Only Student A: {'Math'}
Try it Yourself »

Common Beginner Mistakes

❌ Set को Index से Access करने की कोशिश
fruits = {"apple", "banana"} print(fruits[0]) # TypeError
✅ सही तरीका — loop या in इस्तेमाल करें
for fruit in fruits: print(fruit)
❌ Empty Set बनाने के लिए {} लिखना
empty = {} print(type(empty)) #
✅ सही तरीका
empty = set()
❌ remove() और discard() को Confuse करना
fruits = {"apple"} fruits.remove("mango") # KeyError

अगर value मौजूद होने की गारंटी न हो, तो discard() इस्तेमाल करना ज्यादा सुरक्षित है।

❌ Set में Order की उम्मीद करना

Set में elements का कोई fixed क्रम नहीं होता, इसलिए print करने पर हर बार same order मिलने की उम्मीद नहीं करनी चाहिए।

Exercise ?

अगर किसी Set में एक जैसी value दो बार डाली जाए, तो क्या होगा?

दोनों values save हो जाएंगी
सिर्फ एक ही value रहेगी
Error आएगा

Coding Challenge और Final Revision

अब खुद अपने Online Python Editor में इन challenges को solve कीजिए:

  1. अपने 5 favorite colors की एक list बनाइए जिसमें कुछ duplicate colors भी हों, फिर उसे Set में बदलकर duplicates हटाइए।
  2. दो sets बनाइए और union() से दोनों को मिलाइए।
  3. उन्हीं दो sets पर intersection() और difference() इस्तेमाल करके देखिए।
  4. add() से किसी set में एक नई value जोड़िए, और discard() से कोई value हटाइए।
  5. len() और in का इस्तेमाल करके किसी set की length और किसी value की मौजूदगी check कीजिए।

Quick Revision

ConceptSyntax / Example
Set बनानाfruits = {"apple", "banana"}
Empty Setempty = set()
IndexingPossible नहीं
add()Value जोड़ता है
remove() / discard()Value हटाते हैं (error देने में फर्क)
pop()Random element हटाता है
union() / intersection() / difference()दो sets के बीच combine / common / अलग elements
clear()Set को खाली कर देता है

FAQ

Python में Set क्या है?

Set Python का एक data structure है जिसमें सिर्फ unique values रखी जाती हैं, और इसमें elements का कोई fixed order नहीं होता।

Set और List में मुख्य फर्क क्या है?

List [ ] में बनती है, order maintain करती है, और duplicate values allow करती है। Set { } में बनता है, order maintain नहीं करता, और सिर्फ unique values रखता है।

Set में Indexing क्यों नहीं होती?

क्योंकि Set में elements का कोई fixed क्रम नहीं होता, इसलिए किसी element की कोई तय position (index) होती ही नहीं।

remove() और discard() में क्या फर्क है?

अगर दी गई value मौजूद न हो, तो remove() error देता है, जबकि discard() बिना किसी error के आगे बढ़ जाता है।

Set का सबसे common इस्तेमाल क्या है?

किसी list में से duplicate values हटाना, और दो groups के बीच common, अलग, या मिले हुए elements निकालना — ये Set के सबसे common real-world इस्तेमाल हैं।

Summary

Set = सिर्फ unique values रखने वाला, बिना क्रम वाला container।

इस article में आपने सीखा कि Python Set क्या है, इसे कैसे बनाते हैं, duplicate values अपने आप कैसे हट जाती हैं, Set में indexing क्यों नहीं होती, और add(), remove(), discard(), pop(), union(), intersection(), difference(), clear() जैसे common operations कैसे इस्तेमाल होते हैं।

Set duplicate values हटाने और दो groups के बीच relationship (common, अलग, मिले हुए elements) निकालने के लिए बहुत उपयोगी है। अब ऊपर दिया गया coding challenge खुद अपने Online Editor में solve करें।

Related Articles

🧑‍💻 Python Coding Lab Python code likho, run karo aur practice karo — directly browser mein.