Python set In Hindi | Python Programming In Hindi

Python set In Hindi In Python Programming

Python Programming in Hindi seekhna kaafi interesting aur engaging experience ho sakta hai. Python mein built-in data types jaise list, tuple, set, aur dictionary ka use data collections ko store karne ke liye hota hai. Inme se set ek unique aur powerful data type hai jo humein unchangeable, unordered, unindexed, aur unique values store karne ki facility deta hai. Is article mein hum Python set ko detail mein samjhenge aur seekhenge kaise iska effectively use kar sakte hain.

Python set In Hindi | Python Programming In Hindi
Python set In Hindi | Python Programming In Hindi

Python set kya hai?

Python set ek unordered collection hota hai jisme unique items hote hain. Set me duplicate values nahi hoti hain, aur isme elements ko kisi specific order me store nahi kiya jata. Python set kaafi useful hota hai jab humein kisi collection me se duplicate items ko remove karna hota hai ya phir humein unique elements ka collection maintain karna hota hai.

Read: What is HTML in Hindi - HTML क्या है? विशेषताएं और फायदे

Set ke Features

Python set ke kuch main features hain:

Unordered: Matlab set ke items kisi specific order me nahi hote. Jab aap set me elements ko insert karte hain, toh wo specific order me store nahi hote. Har baar jab aap set ko access karte hain, elements ka order different ho sakta hai.

Unique: Set me duplicate items nahi hote. Agar aap same value ko multiple times insert karte hain, toh set sirf ek hi value ko accept karta hai.

Unchangeable: Set ke items ko aap modify nahi kar sakte. Matlab, aap ek baar set me element add kar dene ke baad usko update ya delete nahi kar sakte. Haan, aap set me naye elements zaroor add kar sakte hain.

Unindexed: Set me elements ka koi index number nahi hota, isliye aap index number se items ko access nahi kar sakte.

Read: वेब ब्राउज़र क्या है? | What Is Web Browser In Hindi

Python set kaise create karein?

Python me set create karna kaafi simple hai. Aap curly braces { } ka use karke set ko define kar sakte hain.

Example:

s1 = {12, 34, 56, 67}
s2 = {True, 'Name', 56.7, 56}

Python set Example

Chaliye ek example dekhte hain jisme hum set create karte hain aur usko print karte hain.

s = {True, 'Name', 56.7, 56}
print(s)

Output:

{True, 'Name', 56.7, 56}

Different Types of Items in Set

Ye zaroori nahi hai ki set me sirf same type ke items ho. Aap apni need ke according kisi bhi type ke elements insert kar sakte hain, jaise String, Boolean, Numeric, etc.

Set ki Length aur Type kaise pata karein?

Python set ki length aur type ka pata karne ke liye hum len() aur type() functions ka use karte hain.

Example:

s = {True, 'Name', 56.7, 56}
print('Set Length:', len(s))
print('Type:', type(s))

Output:

Set Length: 4
Type: <class 'set'>

Set me Iteration kaise karein?

Halaanki set items unindexed hote hain, phir bhi hum inhe for loop ki madad se iterate kar sakte hain.

Example:

s = {True, 'Shyama', 56.7, 56}
print('Iterate using for loop:')
for item in s:
    print(item)

Output:

Iterate using for loop:
56
True
56.7
Shyama

Set me Duplicate Items

Agar aap set me duplicate items insert karte hain, to set sirf unique items ko hi store karega.

Example:

# here 12, 67, and 89 are duplicate.
s = {12, 45, 67, 78, 89, 23, 12, 67, 89}
print(s)

Output:

{67, 12, 45, 78, 23, 89}

I Hope, ab aap samajh gaye honge ki set list aur tuple se kitna different hai.

Python Programming in Hindi

Python programming in Hindi seekhna asaan hai aur iska syntax bhi kaafi easy hai. Python set ko samajhne ke baad, aap Python ke aur bhi data types jaise list, tuple, aur dictionary ko explore kar sakte hain. Python ka syntax simple aur readable hota hai jo beginners ke liye perfect hai.

Set Methods

Python set ke kai useful methods hote hain jo humein set ke elements ke saath kaam karne me madad karte hain. Kuch common methods hain:

add(): Set me ek naya element add karta hai.

s = {1, 2, 3}
s.add(4)
print(s)  # Output: {1, 2, 3, 4}

remove(): Set se specified element ko remove karta hai. Agar element exist nahi karta to error raise karta hai.

s = {1, 2, 3}
s.remove(2)
print(s)  # Output: {1, 3}

discard(): Set se specified element ko remove karta hai. Agar element exist nahi karta to koi error nahi raise karta.

s = {1, 2, 3}
s.discard(2)
print(s)  # Output: {1, 3}
s.discard(5)  # No error

clear(): Set ke saare elements ko remove karta hai.

s = {1, 2, 3}
s.clear()
print(s)  # Output: set()

copy(): Set ki ek shallow copy return karta hai.

s = {1, 2, 3}
s_copy = s.copy()
print(s_copy)  # Output: {1, 2, 3}

union(): Do ya zyada sets ka union return karta hai.

s1 = {1, 2, 3}
s2 = {3, 4, 5}
s_union = s1.union(s2)
print(s_union)  # Output: {1, 2, 3, 4, 5}

intersection(): Do ya zyada sets ka intersection return karta hai.

s1 = {1, 2, 3}
s2 = {2, 3, 4}
s_intersection = s1.intersection(s2)
print(s_intersection)  # Output: {2, 3}

difference(): Ek set me se doosre set ke elements ko subtract karta hai.

s1 = {1, 2, 3}
s2 = {2, 3, 4}
s_difference = s1.difference(s2)
print(s_difference)  # Output: {1}

symmetric_difference(): Do sets ke elements jo common nahi hote unka set return karta hai.

s1 = {1, 2, 3}
s2 = {2, 3, 4}
s_sym_diff = s1.symmetric_difference(s2)
print(s_sym_diff)  # Output: {1, 4}

Python set ke Real-life Applications

Python set ka use real-life applications me bhi hota hai. Kuch common use cases hain:

Data Cleansing: Set ka use duplicate data ko remove karne me hota hai. Jab humein kisi dataset me unique values chahiye hoti hain, tab hum set ka use kar sakte hain.

Membership Testing: Set ka use fast membership testing ke liye hota hai. Kisi element ka set me hona ya na hona check karna kaafi efficient hota hai.

Mathematical Operations: Sets ka use mathematical operations jaise union, intersection, difference, aur symmetric difference ke liye hota hai.

Graph Algorithms: Sets ka use graph algorithms me nodes aur edges ko manage karne ke liye hota hai.

Conclusion

Python Programming in Hindi seekhne ka maza tab aur badh jata hai jab aapko iske powerful data types aur methods ka use karna aata hai. Python set ek aisa hi data type hai jo unique aur efficient data management ke liye use hota hai. Is article me humne set ke features, creation, methods, aur real-life applications ko detail me samjha.

यह भी पढ़ें: 250+ Free Python Projects with Source Code: From Beginner to Advanced

I hope, ab aap Python set ko achche se samajh gaye honge aur isko apne Python projects me use kar payenge. Python Programming in Hindi seekhna kaafi asaan hai aur set jaise data types is journey ko aur bhi interesting banate hain.

यह भी पढ़ें: Python Programming In Hindi | Python Tutorials In Hindi

और नया पुराने

संपर्क फ़ॉर्म