Python tutorial for beginners in Hindi-Chapter 10(Tuple)
Updated: Nov 10, 2020
Tuple in python
Tuple homogeneous और heterogeneous डेटा का एक संग्रह है।
Tuple declare करने के लिए () का हम उपयोग करते हैं ।
Tuple अपरिवर्तनीय है, इसका मतलब है कि हम एक tuple पर modification नहीं कर सकते हैं।
Tuple के elements को access करने के लिए हम index का उपयोग करते हैं।
Tuple positive और negative index की अनुमति देता है।
Tuple +, *, और slice (:) ऑपरेटर की अनुमति देता है।
Example of homogeneous data
T = (10,20,30,40,50)
print(T) #(10,20,30,40,50)
print(T[0]) #10
print(T[-1]) #50
T[2] = 100 #Error(no modification)
Example of heterogeneous data
T = (10,"Python",30,10.25,50)
print(T) #(10,"Python",30,10.25,50)
print(T[2]) #"Python"
print(T[-1]) #50
Packing
हम () का उपयोग किए बिना एक टपल declare कर सकते हैं , इस प्रक्रिया को packing कहा जाता है।
t1 = 10,20,30
print(t1) #(10,20,30)
print(type(t1)) #tuple
Unpacking
Unpacking में, हम इन values को एक single variable में निकालते हैं।
t1 = 10,20,30
a,b,c = t1
print(a) #10
print(c) #30
Tuple में केवल एक element declare करने के लिए हम इसके बाद , का उपयोग करते हैं।
a = (10)
b= (10,)
print(type(a)) #<class 'int'>
print(type(b)) #<class 'tuple'>
Tuple class methods
count(x): returns the number of elements in that is equal to x
index(x): returns the index of 1st item that is equal to x
हम इस chapter में tuple कइ बारे में सीखा। अगले chapter में हम String के बारे में पढ़ेंगे।
अगर आपको chapter wise notes चाहते है तो कमेंट में email id डालें।