Nesting of LIST in Python – जब हम किसी Code में किसी अन्य Code को Specify कर देते हैं, तो इस प्रक्रिया को Nesting करना कहते हैं। Python हमें ये सुविधा देता है कि हम एक List Data Structure में List Items के रूप में न केवल अन्य तरह के Data Types के Data Items की बल्कि स्वयं List Data Structure के Data Items की भी Nesting कर सकते हैं।
उदाहरण के लिए हम एक ऐसा List Object Create कर सकते हैं, जिसमें String, Integer, Float, Dictionary, Tuple आदि विभिन्न प्रकार के Data Items को Store हो सकते हैं। इतना ही नहीं, हम इस List में स्वयं List Data Type के Data Items को भी Store कर सकते हैं और इस Nesting के माध्यम से हम बड़ी ही आसानी से Python में Multi-Dimensional Array या Matrix को Simulate कर सकते हैं, जो कि Multiple Data Types के Data को Hold करने में सक्षम होता है। जैसे-
[code] FileName: ListNesting.py matrix = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] print("The Matrix: \n", matrix) print("\nFirst Row of the Matrix: ", matrix[0]) print("\nCentered Item of the Matrix: ", matrix[1][1]) Output The Matrix: [[1, 2, 3], [4, 5, 6], [7, 8, 9]] First Row of the Matrix: [1, 2, 3] Centered Item of the Matrix: 5 [/code]
इस Example में पहला print() Function पूरे Matrix को Display करता है, जबकि दूसरे print() Statement में हमने Index Number 0 Specify करके Python Interpreter को बताया है कि हमें केवल वह Inner List चाहिए, जिसका Index Number 0 है और अन्तिम Statement में हमने Python को ये बताया है कि हमें Matrix के Index Number 1 वाले Row की Index Number 1 वाले Column में Stored Value को Display करना है।
इस List के विभिन्न Data Items की Position को Access करने के लिए हमें जिन Positions को Index Number के माध्यम से Specify करना होता है, उन्हें निम्न चित्र द्वारा आसानी से समझ सकते हैं-
ये Article इस वेबसाईट पर Selling हेतु उपलब्ध EBook Python in Hindi से लिया गया है। इसलिए यदि ये Article आपके लिए उपयोगी है, तो निश्चित रूप से ये EBook भी आपके लिए काफी उपयोगी साबित होगी।
Python in Hindi | Page: 602 | Format: PDF