Tuple in Python in Hindi – Python Tuple क्या है?
Table of Contents
Toggle
Python Tuple एक ordered collection data structure है जो multiple values को store करता है। Tuple की सबसे important feature यह है कि यह Immutable होती है, यानी create होने के बाद इसकी values बदली नहीं जा सकतीं।
✔ Immutable Data Structure
✔ Faster Than List
✔ Tuple Indexing & Slicing
✔ Real-Life Examples
Python Tuple क्या है?
Python Tuple एक ordered collection data structure है जो multiple values को एक sequence में store करता है। Tuple की सबसे खास बात यह है कि यह Immutable होती है, यानी once create होने के बाद इसकी values को बदला नहीं जा सकता।
student = ("Rahul", 21, "Dehradun")
print(student)
ऊपर दिए गए example में Tuple multiple values को एक single variable में store कर रही है।
Python Tuple का Syntax
Python में Tuple को ( Parentheses ) के अंदर लिखा जाता है। इसमें multiple values comma की मदद से separate की जाती हैं।
# Multiple Item Tuple
data = ("Rahul", 21, 85.5)
# Single Item Tuple
single = ("Python",)
print(data)
print(single)
ऊपर दिए गए example में पहला tuple multiple values store कर रहा है, जबकि दूसरा single item tuple है।
Python Tuple से Data Access कैसे करें?
Python Tuple में data को index number की मदद से access किया जाता है। Tuple indexing support करती है इसलिए specific value को आसानी से retrieve किया जा सकता है।
student = ("Rahul", 21, "Dehradun", "Python")
print(student[0])
print(student[-1])
print(student[1:3])
ऊपर दिए गए example में indexing और slicing की मदद से Tuple data access किया गया है।
Python Tuple में Loop कैसे लगाएँ?
Python Tuple में loop का उपयोग करके सभी values को आसानी से access किया जा सकता है। इसके लिए Python में mostly for loop और कभी-कभी while loop का उपयोग किया जाता है।
languages = ("Python", "Java", "C++")
for lang in languages:
print(lang)
ऊपर दिए गए example में loop की मदद से Tuple की सभी values को print किया गया है।
Python Tuple Methods in Hindi
Python Tuple में कुछ useful built-in methods और functions होते हैं जिनकी मदद से data को search, count और analyze किया जा सकता है।
numbers = (10, 20, 30, 20, 50)
print(numbers.count(20))
print(numbers.index(30))
print(len(numbers))
print(min(numbers))
print(max(numbers))
ऊपर दिए गए example में Tuple methods और functions का उपयोग किया गया है।
Tuple Packing and Unpacking in Python
Python में multiple values को एक single tuple में store करना Packing कहलाता है, जबकि tuple की values को अलग-अलग variables में assign करना Unpacking कहलाता है।
# Packing
student = ("Rahul", 21, "Python")
# Unpacking
name, age, course = student
print(name)
print(age)
print(course)
ऊपर दिए गए example में tuple values को अलग-अलग variables में unpack किया गया है।
Python Tuple vs List in Hindi
Python में Tuple और List दोनों sequence data structures हैं, लेकिन दोनों के features और use cases अलग-अलग होते हैं। Tuple immutable होती है जबकि List mutable होती है।
# List
data_list = [10, 20, 30]
# Tuple
data_tuple = (10, 20, 30)
print(data_list)
print(data_tuple)
ऊपर दिए गए example में List square brackets का उपयोग करती है, जबकि Tuple parentheses का उपयोग करती है।
Nested Tuple in Python in Hindi
जब एक Tuple के अंदर दूसरी Tuple store की जाती है, उसे Nested Tuple कहा जाता है। इसका उपयोग complex और structured data को organize करने के लिए किया जाता है।
students = (
("Rahul", 85),
("Aman", 92),
("Neha", 88)
)
print(students[0])
print(students[1][1])
ऊपर दिए गए example में nested tuple का उपयोग करके student records store किए गए हैं।
Python Tuple के Real-Life Uses
Python Tuple का उपयोग उन situations में किया जाता है जहाँ data को fixed और secure रखना जरूरी होता है। इसकी immutable nature इसे reliable data storage के लिए useful बनाती है।
coordinate = (28.6139, 77.2090)
print(coordinate)
ऊपर दिए गए example में location coordinates को tuple में store किया गया है।
Python Tuple में होने वाली Common Errors
Python Tuple का उपयोग करते समय beginners कई common mistakes करते हैं। इन errors को समझना जरूरी है ताकि coding problems को जल्दी solve किया जा सके।
data = (10, 20, 30)
data[0] = 50
ऊपर दिए गए code में tuple value modify करने की कोशिश की गई है, इसलिए Python error देगा।
Python Tuple Interview Questions in Hindi
Python interviews और Data Analytics interviews में Tuple से जुड़े questions अक्सर पूछे जाते हैं। नीचे कुछ important interview questions दिए गए हैं जो beginners और freshers के लिए उपयोगी हैं।
Python Tuple Practice Programs in Hindi
Python Tuple को अच्छे से समझने के लिए practice programs करना बहुत जरूरी है। नीचे कुछ beginner-friendly programs दिए गए हैं जो आपकी coding और logic-building skills improve करेंगे।
numbers = (10, 40, 25, 60, 15)
print(max(numbers))
ऊपर दिए गए example में tuple की सबसे बड़ी value को find किया गया है।
Python Tuple MCQ Quiz in Hindi
सभी questions attempt करें और अंत में Submit Quiz button पर click करके अपना score देखें।
Immutable
Dynamic
None
{ }
( )
< >
count()
append()
insert()
1
-1
10
