Behind the scene of loops in python
Summary
TLDRThe script is from a Python tutorial series named 'Simply Tea and Python.' The host warmly welcomes the audience and sets a goal to reach 350 comments, encouraging engagement. The tutorial delves into Python's loop mechanisms, explaining iterations using tools like 'for' and 'while' loops. It explores behind-the-scenes operations of loops, the concept of iterable objects, and practical examples including lists and files. The host also touches on error handling with 'Stop Iteration' exceptions and demonstrates file handling techniques in Python, aiming to build a foundational understanding of Python programming.
Takeaways
- 😀 The speaker welcomes the audience to the 'Simply Tea and Python' series and encourages them to support the channel if they enjoy the content.
- 🔍 The video discusses loops and iteration tools in Python, aiming to demystify what happens behind the scenes when loops are executed.
- 📖 The audience is introduced to the concept of 'iterables' in Python, which are objects that can be looped over, such as lists, strings, and files.
- 🛠️ Practical examples are given to illustrate how to open and read files using Python, emphasizing the simplicity of file handling in Python.
- 🔑 The script explains the use of the `next()` function and its role in retrieving the next item from an iterator, which is crucial for loop execution.
- 🔄 The video covers the iteration process in detail, discussing how iterators work with iterable objects and how the loop continues until a 'StopIteration' exception is raised.
- 📝 The importance of understanding the basics of Python, such as file handling and iteration, is emphasized for becoming a proficient programmer.
- 💡 The speaker provides insights into how Python treats iteration tools and how they operate on iterable objects, highlighting the language's flexibility.
- 📚 The script touches on the concept of 'iterators' and their role in pointing to the starting location in memory for loop iteration.
- 🤖 The video includes a practical demonstration of using loops with files and lists, showing how to read lines from a file and iterate over a list using a for loop.
- 🔗 The audience is reminded that understanding these concepts is essential not just for using Python effectively but also for succeeding in technical interviews.
Q & A
What is the main goal of the series 'Simply Chai and Python'?
-The main goal of the series 'Simply Chai and Python' is to teach Python in a simple and enjoyable way, hoping to engage the audience and make learning Python fun.
What is the target the speaker sets for the video in terms of audience interaction?
-The speaker sets a target of 350 comments, encouraging viewers to participate and help reach this number by engaging with the content.
What programming concepts were discussed in the previous video of the series?
-In the previous video, the concepts of loops, specifically break and continue keywords, as well as while loops and for loops were discussed.
What does the speaker want to explore 'behind the scenes' in Python in this video?
-The speaker wants to explore how files are opened in Python, the basics of file handling, and the concept of iterable objects.
What is the difference between 'Iterable' and 'Iterator' as mentioned in the script?
-An 'Iterable' is an object that can be iterated over, meaning it can return its members one at a time, while an 'Iterator' is an object that represents a stream of data and supports traversal through that data.
What are some examples of Iterable objects in Python?
-Some examples of Iterable objects in Python include lists, strings, files, and dictionaries.
How does the speaker describe the process of reading from a file in Python?
-The speaker describes the process of reading from a file using the 'open' method and reading line by line using the 'readline()' method, which is an iterator tool that provides each line one at a time.
What is the purpose of the 'stop iteration' exception mentioned in the script?
-The 'StopIteration' exception is raised to signal the end of an iteration, such as when there are no more lines to read from a file, effectively stopping the loop.
How does the speaker suggest handling the 'StopIteration' exception?
-The speaker suggests handling the 'StopIteration' exception by using a loop that continues to read lines until an empty string is returned, indicating the end of the file.
What is meant by 'behind the scenes' when discussing Python loops and file operations?
-'Behind the scenes' refers to the internal workings of Python loops and file operations, such as how memory addresses are handled, how loops continue to the next item, and how exceptions are managed.
What is the significance of the 'with' statement when opening files in Python as discussed in the script?
-The 'with' statement is significant for file operations because it ensures that files are properly closed after their suite finishes execution, even if an exception is raised at any point.
Outlines
😀 Introduction to the Series and Loops
The speaker warmly welcomes the audience to the series 'Simply Tea and Python' and expresses hope that the viewers are enjoying it so far. They encourage viewers to like the series if they are enjoying it and to help reach a target of 350 comments. The speaker reflects on the previous video where they discussed loops, basic syntax, and keywords like 'break', 'continue', 'while loop', and 'for loop'. They clarify that the aim is to understand what happens behind the scenes when loops are executed in Python and files are opened. The speaker assures that understanding these basics will boost confidence and make programming more enjoyable.
📄 Behind the Scenes of File Operations and Loops
The speaker delves into the basics of file operations in Python, explaining how files are opened and read. They mention that they will not discuss binary files in this session and will leave that for third-party libraries. The speaker uses an analogy to explain loops, comparing them to iteration tools. They introduce the concept of 'iterable objects', which are objects that can be looped through, such as lists, strings, and files. The speaker emphasizes the importance of understanding how these objects work behind the scenes to gain a deeper understanding of Python and improve programming skills.
🔍 Deep Dive into How Python Handles Iteration
The speaker provides an in-depth explanation of how Python handles iteration. They discuss the role of the 'iter' tool, which queries iterable objects to determine what can be looped through. The speaker explains that when a loop is applied to an iterable object, Python sends a method to check if a loop can be applied. They also discuss the concept of 'response' in the context of iteration, highlighting that the response contains the next value to be iterated through. The speaker uses examples and analogies to clarify these concepts and their practical applications in Python programming.
📝 Practical Example of Reading Files Line by Line
The speaker provides a practical example of how to open and read files line by line in Python. They demonstrate the use of the 'open' method and the 'readline' method to read files. The speaker explains that 'readline' is an iterator tool that returns each line of the file one at a time. They also discuss the handling of exceptions, such as the 'StopIteration' exception, which occurs when there are no more lines to read. The speaker emphasizes the importance of understanding these concepts to effectively work with files in Python.
🔁 Understanding Iteration Tools and Their Applications
The speaker further explores iteration tools in Python, explaining how they can be used with different data structures like lists and dictionaries. They discuss the concept of 'iter' and 'next' functions and how they can be used to create iterators manually. The speaker also touches upon the importance of understanding how these tools work under the hood to become a proficient Python programmer. They provide examples and explanations to help viewers grasp these concepts.
📚 Wrapping Up the Discussion on Iteration
In the final paragraph, the speaker summarizes the key points discussed in the video. They reflect on the importance of understanding iteration and how it works behind the scenes in Python. The speaker encourages viewers to practice these concepts and apply them to become better Python programmers. They also express hope that the series has been enjoyable and informative, and they look forward to continuing the journey of learning Python with the audience.
Mindmap
Keywords
💡Loops
💡break and continue
💡Comments
💡PythonAnywhere
💡Files
💡Iterators
💡Iterable Objects
💡Underscore and next
💡Exception
💡StopIteration
💡Memory Address
Highlights
Introduction to the series 'Simply Tea and Python' and the goal of creating a coding community in India.
Invitation for viewers to help reach a target of 350 comments.
Review of loops from the previous video, including basic syntax and keywords like 'break', 'continue', 'while loop', and 'for loop'.
Explanation of what happens behind the scenes when loops are executed in Python.
Introduction to the concept of 'iteration tools' in Python.
Discussion on 'iterable objects', such as lists, strings, and files, and their role in loops.
Differentiating between 'iterable' and 'iterator' objects in Python.
Explanation of how the 'iter' function and the '__next__' method work together in iteration.
The role of the 'StopIteration' exception in ending loops.
Practical demonstration of reading a file line by line using a loop.
How to handle the end of a file with an empty string returned by the 'readline' method.
Using 'while' loops to read files and the importance of checking for the end of the file.
Explanation of how the 'iter' tool works with files and lists differently.
The concept of 'iterator' objects and their memory address reference in lists.
How to manually iterate over objects using 'iter' and '__next__'.
The automatic handling of iteration by Python's default 'for' loop.
The difference between 'iterable' objects and 'iterator' objects when stored in a variable.
Practical example of using 'while' loop for file handling and iteration.
How to use 'range' as an iterable object and its treatment in loops.
Final thoughts on the importance of understanding iteration and behind-the-scenes operations in Python.
Transcripts
हां जी कैसे हैं आप सभी स्वागत है आप सभी
का चाय और कोड में और हमारी इस सीरीज के
अंदर जो कि है सिंपली चाय और पाइथन उम्मीद
करता हूं ये सीरीज अभी तक आपको पसंद आ रही
होगी अगर पसंद आ रही है तो प्लीज कंजूसी
कैसी हो रही है यह
के साथ जब सारे मिलके बैठेंगे अच्छा एक
बेस्ट चैनल बनाएंगे इंडिया का इसको कोडिंग
के लिए तभी तो फिर मजा आएगा उससे कम में
तो मजा भी नहीं आएगा इस वीडियो का हमारा
छोटा सा एक कमेंट टारगेट भी है प्लीज उसको
पूरा करने में हेल्प कीजिएगा मात्र 350
कमेंट्स तो चलिए इस वीडियो में अ आपको अगर
याद हो लास्ट वीडियो के अंदर हमने लूप्स
के बारे में काफी कुछ क्वेश्चंस करे थे
क्वेश्चन क्या बेसिकली सिनेरियो थे और उन
सिनेरियो के दौरान ही हमने सारे ब्रेक
कंटिन्यू जितने भी कीवर्ड्स थे वाइल लूप
फॉर लूप सब पढ़ लिए और समझ में भी आ गए
हमें ठीक है इस इस वीडियो के अंदर
एक्चुअली में मैं कुछ बिहाइंड द सीन
बेसिक्स जाना चाह रहा था अ थोड़ा सा हम
फाइल्स को भी एक्सप्लोर करेंगे किस तरह से
फाइल्स ओपन की जाती है बेसिक फाइल्स
python's फाइल और ये सब अ बाइनरी फाइल्स
के बारे में अभी डिस्कस नहीं करेंगे उनके
लिए थर्ड पार्टी लाइब्रेरीज लगती है उनको
भी हम बाद में देखेंगे बट बेसिकली आपको
मैं बताना चाह रहा था कि जब आप फाइल्स ओपन
करते हो या आप लूप्स चलाते हो तो एक्चुअली
में बिहाइंड द सीन pythonanywhere.com
जो बाकी लैंग्वेजेस ने नहीं किया है इतने
तरीके से बट पाइथन के अंदर थोड़ा सा
रिइमेजिन है लूप बिहाइंड द सीन पे फ्रंट प
तो आपको वही फॉर लूप वाइल लूप दिखता है
लेकिन एक बार बिहाइंड द सीन समझ में आएगा
ना तो और अच्छा लगेगा आपको और कॉन्फिडेंस
आएगा कि हां एक्चुअली में लैंग्वेज मुझे
आती है समझ में आती है तो वही सब आपको
बताते हैं पहले एक छोटा सा डायग्राम
बनाएंगे आपके साथ में क्योंकि पाइथन का जो
लूप का स्ट्रक्चर है सिंटेक्स है वो थोड़ा
सा डायग्राम बेसिस पर ही चलता है तो थोड़ा
सा हम यहां आ जाते हैं और एक डायग्राम
छोटा सा बना लेते हैं अब जो पाइथन के अंदर
है ना ये इतना भी कॉम्प्लिकेटेड प्रोसेस
नहीं है आपको बेसिकली बताते हैं तो पाइथन
ने क्या करा कुछ इटर टूल बनाए या इटरेशन
टूल भी आप बोल सकते हो और पहली बात ये जान
लीजिए ये जो इटरेशन है ना ये एक फैंसी नाम
है लूप्स का ही या फिर चीजों को बार-बार
करने का तो मैं इटरेशन बोलूं तो लूप समझ
जाइएगा लूप बोलूं तो इटरेशन समझ जाइएगा यह
सिर्फ इंग्लिश की कहानी है और कुछ भी नहीं
है ज्यादा तो अब सबसे पहली जो जरूरी चीज
है ना वो कुछ यह है कि जैसे हम यहां पे
आते हैं तो सबसे पहले तो एक टेक्स्ट मैं
कर लेता हूं
इटरेशन टूल्स अ इटरेशन टूल है कौन से
पाइथन में देखिए फॉर लूप आपका एक इटरेशन
टूल है कंप्रीहेंशंस जो
है
कंप्रीहेंशंस और भी है मैप भी है यह सारी
चीजें ना अपने आप में एक इटर टूल के अंदर
ही आती है तो इसको मैं ब्रैकेट में रख
देता हूं यहां पे क्योंकि ये सारे ना
टूल्स ही है आपके और कुछ भी नहीं है तो
पहला तो हमारे पास यह हुआ कि एक हमारे पास
में इटर टूल है और यह हो गया काम अब इटर
टूल ही क्यों फॉर लूप तो बेसिकली फॉर एक
अपने आप में कीवर्ड होता है जो यह काम
करता है नहीं नहीं पाइथन इनको इस तरह से
नहीं देखता है पाइथन देखता है कि ये
इटरेशन के टूल्स हैं अब इटरेशन के टूल
सिर्फ उसी पर काम आ सकते हैं जो कि
इटरेटेड हो तो यह एक कांसेप्ट आपको और
समझना पड़ेगा यह वैसे तो होता सभी
लैंग्वेजेस में है बट कई बार बात नहीं की
जाती है इस परे और ज्यादा कुछ होता भी
नहीं इतना बात करने के लिए बट आपके पास
होते क्या
है इटरेटेड
ऑब्जेक्ट्स
अगर स्पेलिंग सही लिखी तो ठीक है इटरेटेड
ठीक है ठीक ही लग रही
है एक्चुअली मैं इसको इटरेबल ऑब्जेक्ट्स
बोला जाता है वैसे तो ठीक है बट इटरेटेड
ऑब्जेक्ट्स बोलो इटरेबल ऑब्जेक्ट्स ठीक है
थोड़ा सा इंग्लिश का मुझे भी लग रहा है
मुझे जहां तक ध्यान है इन को इटरेटेड नहीं
इटरेबल ऑब्जेक्ट्स बोला जाता है सही
इंग्लिश में बट ठीक है चलेगा अब ये इटरेबल
ऑब्जेक्ट्स होते कौन से हैं देखिए इन
ऑब्जेक्ट्स के अंदर आपको दिखेगा कुछ इस
तरह के एग्जांपल्स जैसे कि हमारे पास हो
गया लिस्ट्स हो गई यह सबसे कॉमन दिखेगा
स्ट्रिंग्स भी अपने आप में एक है और एक
एग्जांपल मैं यहां जान पूछ के लेना
चाहूंगा जो है फाइल फाइल भी एक इटरेबल
ऑब्जेक्ट है लेकिन उसका जो इंप्लीमेंटेशन
है ना इटर ऑब्जेक्ट्स का वो थोड़ा सा अलग
है कंपेयर टू आपकी रेगुलर लिस्ट से लिस्ट
पे तो हमने कई बार लूप लगाया एक एरे लिया
1 2 3 4 5 वैल्यू डाली फॉर आई इन लिस्ट
प्रिंट आई तो ये सब काम तो हमने किया है
अच्छा ये तो हो गया बेसिक कि ठीक है आपके
पास ये ट्रीटेबल ऑब्जेक्ट है इस तरह से
लेकिन अब यहां पे इसको भी हम एक बॉक्स के
अंदर डाल देते हैं ठीक है आप का भी काम हो
गया है अब यहां पे एक और चीज आती है जो कि
है रिस्पांस जिस रिस्पांस को हम एक्चुअली
में अ बोलते हैं अंडर अंडरस्कोर दो
अंडरस्कोर है यहां पे अ नेक्स्ट और फिर
अंडरस्कोर अंडरस्कोर इसके दो-तीन तरीके और
भी हैं अ बताने के कई बार आप इसको एज अ
नेक्स्ट और पेंसिस भी लिख लेते हो वो भी
मैं आपको बताऊंगा बट यहां पे इसको बोलते
हैं रिस्पांस ठीक है इसको मैं अभी नेक्स्ट
ही ले लेता हूं यहां पे और इसको भी एक
बॉक्स में बंद कर लेता हूं यह बहुत काम
आएगा
python3 बेसिकली चीजें हैं एक तो आप
अंडरस्कोर अंडरस्कोर नेक्स्ट अंडरस्कोर
अंडरस्कोर और एक आपका है इटरेबल
ऑब्जेक्ट्स जो कि लिस्ट फाइल है जिस पर भी
आप लूप लगा रहे हो बेसिकली और एक लूप
लगाने का टूल लूप लगाने के कई टूल होते
हैं जैसे फॉर हो गया कंप्रीहेंशन भी देखा
था वो देखा स्टार्टिंग में हम वैल्यू लिख
देते हैं फिर लूप लिखते हैं तो वह भी एक
तरह का टूल है
और मैप भी आप देखोगे इस तरह से अब होता
क्या है स्टेप वन के अंदर क्या होता है
सबसे पहले तो यह इटर टूल जो है यह क्वेरी
करते हैं इटरेबल ऑब्जेक्ट से कि सबब मुझे
आपके ऊपर लूप लगाना है तो वो क्या करता है
आपको सबसे पहले यहां पर आपको भेजता है एक
इटर ऑब्जेक्ट या आप इटर बोल दीजिए इटर
मेथड भेजता है कि देखो मुझे आपके ऊपर एक
लूप भेजना है तो उसको हां इंटरनल भीसी नाम
से जाना जाता है तो इसने भेजा एक मेथड कि
मुझे लगाना है इटरेटेड ऑब्जेक्ट्स पे एक
लूप तो एक इटर मेथड यहां पे भेजता है कि
क्या मैं लगा सकता हूं तो इसके रिस्पांस
में यूजुअली आता है कि हां आप लगा सकते हो
लेकिन रिस्पांस में सिर्फ आपके पास ये
नहीं आता है कि आप लगा सकते हो आपके पास
रिस्पांस में एक्चुअली में नेक्स्ट वैल्यू
आती है है तो ये जो इटर ऑब्जेक्ट्स है ना
ये आपके पास जाते हैं और एक नेक्स्ट भेजते
हैं कि साहब अब आपको मैं एक नेक्स्ट
रिटर्न कर रहा हूं अगर आपके पास रिटर्न
में नेक्स्ट आता है ये अंडरस्कोर अंडर
नेक्स्ट तो आपके पास जो फर्स्ट वैल्यू है
क्योंकि देखिए क्या आपने सोचा है कभी कि
इस तरह से जब आप एक कोई एरे लेते हैं सपोज
करिए हमारा एरे है या लिस्ट है जिसके अंदर
आपके पास वैल्यूज है 1 2 3 4 अ तो इसको
पता कैसे लगता है कि एक्चुअली में फोर
वैल्यू आ गई है ये फोर के बाहर क्यों नहीं
जाता है बाउंड्रीज को क्रॉस क्यों नहीं
करता है और इसको कैसे पता है फर्स्ट
वैल्यू यहीं से स्टार्ट करना है ये यहां
से स्टार्ट क्यों नहीं करता है यह सारा जो
जितना भी क्वेश्चंस है ना यह क्वेश्चंस के
आंसर एक्चुअली में नेक्स्ट में जाते हैं
इटरेबल ऑब्जेक्ट्स आपको हमेशा मेमोरी के
स्टार्ट लोकेशन पे पॉइंट करता है कभी भी
आपको पूरा लिस्ट नहीं देता है वोह आपको
पॉइंट करता है यहां से लूपिंग स्टार्ट
करनी है क्योंकि यहां से आपको कंटीन्यूअस
मेमोरी एलोकेशन मिल रहा है तो जब भी आप
इटरेबल ऑब्जेक्ट्स को देखोगे तो आपको एक
रिटर्न में एक ऑब्जेक्ट में मेमोरी एड्रेस
मिलता है वह आपके स्टार्ट पॉइंट पे होता
है प्लस आपको साथ में मिलता है यह नेक्स्ट
अब ये नेक्स्ट क्या कर करता है जब तक आपको
नेक्स्ट मिल रहा है ना तो जो मेमोरी
एड्रेस है वहां पे जो वैल्यू है वो तो आप
प्रिंट कर ही दोगे क्योंकि वो तो आ ही रही
है आपके पास में लेकिन अगर आपके पास में
नेक्स्ट आया इसका मतलब है और भी लूप लगाया
जा सकता है आगे और वैल्यू है मेमोरी
एड्रेस में और वैल्यूज एजिस्ट करती है तो
ये जब वैल्यू आती है आपके पास में तो फिर
ये जो इटर टूल है ना यह क्या करते हैं ये
इटर टूल के पास जैसे ही नेक्स्ट आता है तो
हम क्या करते हैं इसको बार-बार से नेक्स्ट
नेक्स्ट नेक्स्ट करवाते जाते हैं तो आपके
पास कुछ इस तरह से होता है कि अभी मैं
करके भी दिखाऊंगा सारा प्रैक्टिकल चिंता
मत करो नेक्स्ट अब ये नेक्स्ट पैरेंस से
लिखो चाहे अंडरस्कोर अंडरस्कोर नेक्स्ट
लिखो एक ही बात है तो आप ये नेक्स्ट
नेक्स्ट नेक्स्ट करते रहते हो तो जितनी
बार नेक्स्ट करते हो उतनी बार वैल्यू आपकी
प्रिंट होती जाती है तो ये कुछ इस तरह से
नेक्स्ट नेक्स्ट तो होता जाता है अब फाइनल
जब नेक्स्ट आता है जब आप फोर पे पहुंच गए
हो तब आपके पास एक एक्सेप्शन रेज होता है
स्टॉप इटरेशन एक्सेप्शन तो वो जैसे
एक्सेप्शन रेज होता है तब पता लग जाता है
कि देखो साहब एक्सेप्शन आ गया है अब आगे
और वैल्यूज नहीं है तो आगे नहीं जाएंगे हम
यह पूरी कहानी होती है बिहाइंड द सीन तो
तीन इसके अंदर मेजर किरदार हैं तीन हीरोज
बोल सकते हैं कि एक तो आपका इटर टूल होगा
ही होगा फॉर हो सकता है कॉम्प्रिंट हो
सकते हैं कुछ भी हो सकते हैं और
pythonanywhere.com अब इस थ्योरी को हमें
प्रैक्टिकल में भी तो उतारना पड़ेगा
क्योंकि एक्चुअली में तो आपको समझ में तो
सारा अच्छे से ज्यादा तो वहीं पे आएगा ठीक
है तो अब हम क्या करते हैं थोड़ा सा बेसिक
प जाते हैं लेकिन आपको मैं एक चीज और बता
दूं थोड़ा सा एक्सेप्शन होता है फाइल्स के
अंदर तो फाइल से भी भेड़ लेते हैं इतना
सोचना समझना क्यों चलिए तो अब हम चलते हैं
यह तो हो गया हमारा काम बेसिक फाइल को
थोड़ा सा अलग ट्रीट करना है बस और कुछ भी
नहीं है हम यह सारा का सारा काम करेंगे
टर्मिनल पे क्योंकि वहां पे इजीली आपको सम
समझ में आएगा अच्छा सिर्फ टर्मिनल यहां
नहीं ओपन करना है मुझे मैं एक नया फोल्डर
ही बना लेते हैं और इसको बोल देते हैं
04
अंडरस्कोर इटरेशन इटरेशन टूल्स बोल लीजिए
इटरेशन टूल्स बोल लेते हैं और इसके अंदर
मुझे एक नई फाइल बनानी ही पड़ेगी क्योंकि
वरना स्क्रिप्ट ओपन क्या करेंगे तो इसको
बोल देते हैं स्क्रिप्ट या चाय बोल देते
हैं ठीक है यड पवा ठीक है काफी देर हो गई
चाय से कुछ काम भी नहीं किया यहां पर आप
कुछ भी अपना कोड लिख दीजिए जैसे आपको
इंपोर्ट करना है टाइम क्यों करना है पता
नहीं बट कर लीजिए उसके बाद आप कुछ प्रिंट
करवा दीजिए प्रिंट करवा दीजिए चाय इज हियर
ठीक है और इसके बाद सपोज करिए आपको कुछ
वेरिएबल चाहिए ठीक है यूजर नेम आपने
वेरिएबल लिया और इसको मैंने लिख दिया
हितेश डायरेक्ट तो नहीं लिख सकता ये लीजिए
और फिर इसको भी प्रिंट करवा दीजिए क्यों
करवाना है वो कुछ नहीं पता बस एक फाइल
चाहिए थी क्योंकि टेक्स्ट फाइल में काम
काम करोगे तो इतना मजा नहीं आता है तो यह
लीजिए यह आपकी एक बेसिक चार लाइन का कोड
है और हम इस कोड को काम में लेना चाहते
हैं अब मैं इस फाइल को क्लोज कर देता हूं
काम इसका कुछ नहीं था राट क्लिक करिए
इटरेशन टूल पे और ओपन एंड इंटीग्रेटेड
टर्मिनल क्लिक करिए अब हुआ इससे क्या कि
जैसे ही आप एलएस करोगे तो आपको ये फाइल
दिख जाएगी मैं नहीं चाहता था कि लॉन्ग पाथ
दूं मैं उसी फाइल के अंदर उसी डायरेक्टरी
में रहना चाहता हूं वहीं पर ओपन कर लेता
हूं अपने python3 शेल को और अब हम आ गए
हैं पाइथन के अंदर ठीक है अब आप सोच रहे
होंगे कि फाइल ओपन करना पाइथन में ना कुछ
बहुत बड़ा एक काम होता होगा या कुछ इस तरह
से होता होगा नहीं नहीं इतना बड़ा कुछ काम
नहीं है आपको जब भी फाइल ओपन करनी है आप
सीधा ही ओपन करिए यह लीजिए ओपन मेथड पाइथन
के अंदर बाय डिफॉल्ट होता है स्ट्रिंग के
अंदर आप वैल्यू पास कर दीजिए जो भी आपकी
वैल्यू है तो हमारे पासड
के पास रेफरेंस हो गया अब आप कई बार
देखेंगे जब ये रेफरेंस आपके पास आ गया है
तो आपके पास कई मेथड्स हैं अब इस फाइल को
रीड करने के लिए तो एक सबसे कॉमन मेथड जो
आपको मिलेगा वो मिलेगा एक ये रीड लाइन
करके कि आप एक लाइन इसमें से रीड कर दीजिए
क्योंकि एक्चुअली में अगर आप फाइल को
थोड़ा सा और ब्रॉडली देखोगे तो फाइल के
अंदर है क्या मेमोरी में जाने के बाद तो
वो लाइंस ही है तो वही एरे जैसा ही काम है
कि हर लाइन पे कुछ ना कुछ लिखा हुआ है तो
ये रीड लाइन कुछ ना कुछ इसी तरह से काम
करता है ये भी अपने आप में एक इटरेटर टूल
ही है जो आपको एक-एक लाइन यहां पे रीड
करके दे रहा है फर्स्ट इंपोर्ट टाइम किया
और वापस से करोगे तो इसने कहा कि प्रिंट
चाय इज हियर यही हमने लिखा था उसके बाद
आपने फिर किया तो इसने यूजर नेम दिया उसके
बाद प्रिंट भी करा लिया लेकिन अब मैं
दोबारा से करूंगा तो क्या होगा क्योंकि ये
जो चीजें है ना रीड लाइन ये इंप्लीमेंटेड
है python2 तो इन्होंने एक्सेप्शन ना बड़े
प्यार से हैंडल कर रखा है तो जैसे ही आप
करोगे फाइनल आपको ये जो एमटी स्ट्रिंग मिल
रही है मतलब अब लाइन ब्रेक हो गया है अब
इसके बाद दोबारा करने चाहोगे तो ये हर बार
आपको यह देगा क्योंकि एक्सेप्शन रेज हो
गया है आप आपकी फाइल कंपलीटली रीड हो चुकी
है ठीक है यह तो हमारा बेसिक तरीका था
लेकिन अब जो इंटरेस्टिंग बात है ना वो
करते हैं अब हम अब हम क्या करते हैं इसको
वापस से रन कराते हैं क्योंकि एक्चुअली
में ना मुझे वापस से फाइल रीड करनी है
अच्छा अभी मैं वापस से क्यों चला रहा हूं
क्योंकि अभी जो इस फाइल के अंदर होगा ना
अब वापस से आपकी फाइल लोड हो गई है इसके
अंदर इस वेरिएबल के अंदर अब हमने अभी तक
तो देखा था कि इसके पास मेथड है बट मैंने
आपको बताया कि एक जो मेथड है अंडरस्कोर
अंडरस्कोर नेक्स्ट अंडरस्कोर अंडरस्कोर ये
भी अवेलेबल है ये कोर सिंटेक्स है जो कि
इटरेटेड बनाता है चीज को तो इसको अगर आप
पैरेंस के साथ जैसे ही रन करोगे तो आउटपुट
आपके पास एगजैक्टली सेम आया लेकिन यह रॉ
तरीका है जैसा
python2 में है ना वो क्रशिंग वाला पार्ट
नहीं होता कैसे बताता हूं इंपोर्ट टाइम तो
तो आ गया प्रिंट चाय भी आ गया चाय इज हियर
नेक्स्ट आपको भी पता है यूजर नेम लिया था
और इस यूजर नेम को प्रिंट करवाया था इसके
बाद क्या जब आप रीड लाइन मेथड यूज़ कर रहे
थे जो आपको अक्सर सारे ट्यूटोरियल्स में
सारे टीचर्स सब पढ़ाते हुए नजर आएंगे
लेकिन रॉ तरीके में क्या वो रीड लाइन भी
तो कैसे ना कैसे डिफाइन हुआ होगा किसी ने
कोडर ने कोड लिखा होगा तो यहां पे जब आप
करते हो तो देखो अब हमारे पास में एक
एक्सेप्शन रेज हुआ है स्टॉप इटरेशन तो रीड
लाइन कहीं ना कहीं बिहाइंड द सीन इस
एक्सेप्शन को अच्छे से हैंडल करके आपको
रिटर्न कर रहा है एमटी स्ट्र
ठीक है यही बेसिक काम है इसी तरह से काम
होता है वैसे बाय द वे ये तो हमने एक-एक
करके कराया आप चाहो तो इसको लूप में भी कर
सकते थे लूप के अंदर भी कोई ज्यादा ऐसे
प्रॉब्लम नहीं है फाइल्स ओपन करके रीड
करने में तो आप बहुत आसानी से कर सकते हो
क्योंकि ट्रेबल है वो और ट्रेबल ऑब्जेक्ट
है फाइल अपने आप में तो आप सारे इटरेशन के
टूल्स यूज कर सकते हो अभी तो हमने रीड
लाइन एक टूल यूज करा आप चाहो तो और भी कर
सकते हो जैसे मैं बोल दूं फॉर लाइन
वेरिएबल का नाम है कुछ भी रख सकते हो इन
अब ओपन ही तो करना है ओपन करते तो इटरेबल
बन जाता है वो तो ओपन करके आप उस
स्क्रिप्ट को ले लीजिए
स्क्रिप्ट है हमारी चाय ड पवा यह लीजिए
चाय आ गई अब यहां पर आपको कई लोग ना इसके
बाद आपको दिखेंगे डॉट रीड लाइंस एक यह भी
मेथड होता था पुराना रीड लाइंस अब आपको
कोई लाइन नहीं लाइंस यह मेथड अब आपको कोई
यूज करता हुआ नजर नहीं आएगा क्योंकि यह
मेथड एक्चुअली में मेमोरी पर थोड़ा सा
भारी पड़ता है तो इसीलिए अभी की डेट में
आपको सिर्फ यह ओपन इस तरह से ही सारे
प्रोजेक्ट मिलेंगे बट जस्ट फॉर फन आपको
बता दिया कि हां रीड लाइंस भी यूज करते
हैं कई लोग य आपने कर लिया अब देखिए अब
आपको करना क्या है अब आपको प्रिंट ही
करानी है लाइन बस और कुछ भी नहीं करना है
तो यहां पर मैं टैब करके करता हूं और इसको
प्रिंट करा दीजिए पूरी
लाइन अच्छा अब सबसे इंटरेस्टिंग बात हम कि
ये लाइन तो हम प्रिंट करा देंगे चलिए एक
बार देखते हैं होता क्या है ये लीजिए इसको
कैसे पता लगा कि डबल कोट्स जब आए एमटी
स्ट्रिंग आ तब मुझे खत्म करना है इस लूप
को कभी सोचा इस बारे में हां जी क्योंकि
यह सब है क्या यह सब इटरेटेड टू टूल्स हैं
इन टूल्स के अंदर ऑलरेडी यह प्रोग्रामिंग
की गई है कि किस तरह से फाइल को रीड करना
है किस तरह से एमटी आए तोब आपको हटना है
यह सारा काम इसके अंदर दे रखा है कि कैसे
आपको काम करना है अब सबके बीच में एक-एक
लाइन इसलिए आ गई है क्योंकि वहां पे जो
स्लैश एन है ना वो प्रॉपर्ली रीड नहीं
होता है प्रिंट इसके अंदर तो आप चाहो तो
इसको कुछ इस तरह से लिख के और यहां पे हम
प्रिंट लाइन ये है तो एंड और यहां पे
डिफाइन कर सकते हैं कि यार एंड को है ना
आप अ एंटर से मत करना इसको हम जस्ट डबल
कोट से कर देते हैं तो अपना काम इससे भी
हो जाता तो बेसिक है ये ठीक है जी यह तो
हो गया हमारा बेसिक कि ठीक है इस तरह से
लाइंस रीड होती है आप यह सारा काम कर सकते
हो और वैसे तो वाइल लूप से भी कर सकते हो
वो भी चाहो तो मैं करके दिखा दूंगा लाइन
अच्छा वाइल लूप के अंदर थोड़ा सा एक
सिंटेक्स चेंज होगा करें चलिए लव वाइ लूप
भी कर लेते हैं चलिए आप बोल ही रहे तो तो
देखिए हमें पहले तो इस तरह से हम ओपन कर
रहे थे तो हमें एक रेफरेंस चाहिए यह रहा
कि ओपन करा इस फाइल को वाइल लूप से इसलिए
करते है क्योंकि वाइल लूप के अंदर ना फॉर
की तरह वो सिंटेक्स नहीं आता है जैसे फॉर
लाइन इन किसके अंदर वाइल लूप में तो ट्रू
फॉल्स ही जाता है सीधा तो वाइल आपने लिखा
और ट्रू तो तभी तो आप वाइल लूप के अंदर
जाओगे तो ये सिंटेक्स थोड़ा सा चेंज हो
जाता है अब इसके अंदर क्या करना है कि
आपको एक-एक करके लाइन रीड करनी पड़ेगी तो
हमारी जो लाइन है उसको रीड करना पड़ेगा अब
यहां पे आपके पास ज्यादा ऑप्शन नहीं है तो
f जो भी आपने लिया है डॉट रीड लाइन तो ये
हमारा मेथड हो गया ये लीजिए रीड लाइन से
ठीक है जी अब नेक्स्ट क्या करना पड़ेगा कि
अगर लाइन है ही नहीं तो ब्रेक कर दो लूप
को यही तो हमने पढ़ा था कि जब भी आपको लूप
से बाहर आना है ब्रेक कर दो उसको तो यहां
पर क्या है इफ नॉट लाइन है ये नॉट भी अपने
आप में कीवर्ड है इसके बारे में भी हम बात
करेंगे आगे जाके बस नॉट लाइन का मतलब है
मैं वो भी बता दूंगा नॉट लाइन मतलब जब कुछ
हो ही नहीं आपके पास में तो हम क्या
करेंगे इफ नॉट
लाइन तो यही एक ही लाइन में लिख लेते हैं
इसको तो ब्रेक और वरना क्या करो अगर लाइन
के अंदर कुछ है तो हम प्रिंट करा देंगे उस
लाइन को ये लीजिए प्रिंट करा देते हैं
लाइन और एंड को हम यह लीजिए सिंगल कोड्स
में रख देते हैं ठीक है तो देखो वही एक्ट
आउटपुट आया है लेकिन हमारा लाइन ब्रेक हो
गया जब लाइन के अंदर कुछ नहीं है एमटी
स्ट्रिंग्स है तो उसको हम ट्रीट कर देते
हैं ओके एक छोटी सी चीज और बताना चाहूंगा
मैं यहां पर आपको सपोज
करिए टेस्ट
है अब इस टेस्ट के अंदर हम कुछ वेरिएबल
में वैल्यू डालते
हैं तो सपोज करिए इसमें मैं वैल्यू डालता
हूं
अ ये लीजिए हितेश अब यहां पर आप इसको
टेस्ट करके देखिएगा
कि नॉट हितेश इन लॉ इफ नॉट इन टेस्ट या
फिर वो जो अभी हमने सिंटेक्स लिखा इफ नॉट
हितेश तो क्या होता है इफ हितेश होता है
तो क्या होता है जैसे सपोज करिए आप लिख
दीजिए इफ नॉट टेस्ट तो हम यहां पर क्या
करेंगे इफ नॉट टेस्ट तो इसको हम प्रिंट
करवा लेते
हैं और इसको लिख देते हैं चाय
यह सिर्फ आपको बेसिक बताने के लिए कैसे हो
रहा है एंटर करा अभी आपके पास कुछ भी नहीं
आया क्योंकि नॉट टेस्ट वैल्यू पास नहीं
हुई अब हम चलते हैं वापस से इसके अंदर हम
डाल देते हैं एमटी स्ट्रिंग ठीक है अब हम
इसको वापस से कराते हैं इफ नॉट
टेस्ट तो प्रिंट चाय तो आपके पास चाय
प्रिंट हो गई तो बस इतना सा ही था इसमें
कुछ ज्यादा ऐसे कोई बड़ी सोचने वाली बात
नहीं है यह सिर्फ टेस्ट करता है कि उसके
अंदर कोई वैल्यू है या नहीं और ट्रू और
फाल्स आपको रिजल्ट देता
है ठीक है यह तो हो गई बात हमारी बेसिक अब
वापस से आते हैं हम थोड़ा सा इटरेशन की
तरफ कि ठीक है हमने स्क्रिप्ट और इन सब का
तो देख लिया कि किस तरह से एक्सेप्शन आते
हैं यह मेथड्स आप कैसे कॉल करते हो यह सब
भी हमने देख लिया बेसिक बेसिक अब आपको
थोड़ा सा और लेके चलते हैं इटरेशन टूल्स
की तरफ कि फाइल से तो आपने देख लिया
फाइल्स अब आपको समझ में भी आ गया रीड लाइन
मेथड है स्टॉप इटरेशन एक्सेप्शन आता है
थोड़ा सा अरेज के साथ या हमारे लिस्ट के
साथ भी थोड़ा सा खेल लिया जाए अब सपोज
करिए अ इसको बोल बोल देते हैं माय लिस्ट
जो भी आपका नाम देना है आप दे दीजिए और यह
हमारे पास में हमने देखा कि 1 2 3 4 यह
लीजिए फोर वैल्यूज दी इसके ऊपर भी तो
हमारे इटरेटेड टूल्स हैं जो काम करते
होंगे तो क्या यहां पर भी व अंडरस्कोर
अंडरस्कोर नेक्स्ट वगैरह वो सब काम में
आता है ये इंटरेस्टिंग बात कही आपने तो हम
क्या करते हैं एक्चुअली में अब आपको मैं
इटर टूल्स ही बताता हूं सीधा आपको ध्यान
हो तो मैंने आपको दिखाया था कि इटर टूल्स
जो होते हैं अच्छा फाइल के अंदर तो हमने
कोई इटर टूल प बात नहीं करी उस परे भी
करेंगे क्योंकि फाइल का खुद का इटर टूल
होता है ये पाइथन के अंदर बाय डिफॉल्ट है
जैसे आपने कहा ना f इक्वल्स ओपन फाइल नेम
तो उसका इटर टूल खुद आता है लेकिन लिस्ट
वगैरह या बाकी किसी के साथ नहीं आता है
फाइल अपने आप में एक इंटरेस्टिंग चीज है
बाकी किसी के साथ नहीं आता है तो आप क्या
कर सकते हो कहीं पे भी बोल सकते हो कि मैं
इटर हां जी अपने आप में एक कीवर्ड है और
अपने आप में एक मेथड है आप इसके बारे में
और डिटेल में भी पढ़ सकते हो तो इसके अंदर
आप कोई भी इटरेटेड ऑब्जेक्ट दे सकते हो
इटरेबल ऑब्जेक्ट्स ज्यादा ठीक होगा
इटरेटेड ऑब्जेक्ट्स जो जो भी आप कहे तो यह
माय लिस्ट मैंने यहां दे दिया अब इस पूरे
का रेफरेंस मैं ना अपने किसी वेरिएबल में
होल्ड कर सकता हूं पाइथन इसीलिए ज्यादा
जानी जाती है सपोज करिए मैं इसको आई ही
बोल देता हूं कैपिटल आई कि आई के अंदर अब
हमारा पूरा इटर माय लिस्ट है पर आई के
अंदर एक्चुअली में है क्या कुछ भी नहीं है
इसने बोला कि मैं हूं एक लिस्ट इटरेटर जो
कि पॉइंट कर रहा हूं ऑब्जेक्ट एक्ट इस
मेमोरी लोकेशन पे तो हमने जो ये लिस्ट
बनाई ना तो वहां पर मेमोरी लोकेशन पर अब
आप पॉइंट कर रहे हो ठीक है तो यही तो हमने
देख अभी एग्जांपल के अंदर कि आपको मिलता
क्या है जैसे आप इसको इटर ऑब्जेक्ट के
लेते हो तो यहां पे तो आपके पास जो इटर
टूल है जो भी इटर टूल आप यूज कर रहे हो
फॉर यूज कर रहे हो या हमने मैनुअल यहां पर
यूज कर लिया है तो उसके अंदर आपको मिलेगा
क्या उस ऑब्जेक्ट का फर्स्ट रेफरेंस
मेमोरी का स्टार्टिंग पॉइंट अब यह क्योंकि
आई आपके पास आ ही गया है ठीक है तो आपको
पता ही है कि अगर वैल्यूज होगी तो वहां पर
मैं क्या बोल सकता हूं डॉट अंडर अंडरस्कोर
नेक्स्ट अंडरस्कोर अंडरस्कोर और इस तरह से
प्रिंट करवा सकता हूं अब क्योंकि अभी आपका
मेमोरी लोकेशन फर्स्ट पे है वहां पे तो
आपका वन आ गया लेकिन अब i के अंदर वैल्यू
क्या है तो अब आप देखोगे i के अंदर वैल्यू
तो एगजैक्टली सेम है तो ऐसा नहीं है कि वो
मेमोरी रेफरेंस पे आप वहां आ गए तो मेमोरी
रेफरेंस भी चेंज करता जाता है ये सारे काम
इंटरनली नेक्स्ट कर रहा है कि मैं तो
फर्स्ट पे ही पॉइंट करूंगा लेकिन अभी
इंटरनली एक पॉइंटर है जिसको मैं रख रहा
हूं वो फर्स्ट उसका हो चुका है अब अब वो
सेकंड पे अपने आप जाएगा तो ये ऐसा नहीं है
कि मेमोरी रेफरेंस चेंज होता है मेमोरी
रेफरेंस से जो लिस्ट इटरेटर है वो हमेशा
स्टार्टिंग पे ही पॉइंट करेगा अ हां ये
इंटरव्यूज में पूछा जाता है समझ में आया
क्यों बहुत सारे लोग इंटरव्यूज फेल करते
हैं पाइथन के हां पूछते हैं ऐसे सवाल आपको
आती है ना पाइथन आप कह रहे हो तो ये सब तो
पता होना चाहिए ओके अब चलते हैं वापस से
आई नेक्स्ट अब किस पे जाएगा टू पे गया
थ्री पे गया फोर पे गया अब क्या होगा अब
आपको पता है क्या होगा ये एग्जैक्ट पॉइंट
पे अब आपको पाइथन का नॉलेज है ठीक है
स्टॉप इटरेशन हमारा एक्सेप्शन रेज हो गया
मतलब हमने पूरा लिस्ट इटरेट कर लिया है अब
आगे और कुछ भी नहीं है तो हमारे जो
नेक्स्ट है फर्द और किसी को पॉइंट नहीं कर
रहा है अच्छा जी ठीक है यह तो हो गया
हमारा
बेसिक अब एक चीज आपको बता देते हैं कि
वापस से हम आते हैं थोड़ा सा बैक यह सब
बताने के लिए कि यह जो इटर ऑब्जेक्ट है
अपना फाइल्स के अंदर बाय डिफॉल्ट होता है
जैसे कि मैंने लिखा एफ इक्वल्स ओपन करते
हैं फाइल को वापस से जो भी उस फाइल के
अंदर था चाय डट
पवा और ये लीजिए ठीक है जी यह तो हमें आता
था इतना बेसिक तो ठीक था अब अब अगर आप सोच
रहे हो कि ये जैसे मैंने रेफरेंस लिया था
लिस्ट के अंदर भी तो ऐसे ही लिया था सेम
कि लिस्ट एक डिक्लेयर करी थी उसको एक
वेरिएबल में डाला था बोला था माय लिस्ट और
सिंटेक्स क्या था कुछ इस तरह का था आपको
याद हो
तो ओके हां ये वाला सिंटेक्स था कि अब इटर
के अंदर माय लिस्ट डाल दिया और उसका
रेफरेंस हमने होल्ड कर लिया लेकिन आपको यह
फाइल के अंदर ऐसा करने की जरूरत नहीं है
क्योंकि ये जो एफ है ना ये अपने आप
बिहाइंड द सीन इस तरह से वर्क कर चुका है
यही डिफॉल्ट पाइथन की प्रोग्रामिंग है कि
इसी तरह से काम करता है आप चाहो तो इससे
पूछ भी सकते हो कि यह जो इटर एफ मैं
बनाऊंगा इज एफ तो क्या ये सेम चीज है आपको
याद है इससे पूछ रहे थे हम इज करके क्या
ये दोनों सेम है हां जी एगजैक्टली सेम है
ठीक है आप इससे यह भी पूछ सकते हो कि अगर
मैं बोलूंगा वैसे तो एफ से ही पूछ सकते हो
आप बट अगर आपको और जाना है जैसे नेक्स्ट
है वैसे इसको ऐसे भी पूछा जा सकता डॉट
अंडर अंडरस्कोर इटर अंडरस्कोर अंडरस्कोर
और यह मेथड जैसे नेक्स्ट था ना वैसे ही
सेम है आंसर इसका भी सेम आएगा बट ऐसे अब
कोई नहीं पूछता है बट हा आंसर वही ट्रू
आएगा दोनों में एक ही बात है यह आपने बोल
दिया या फिर आपने यह बोल दिया या फिर आपने
यह बोल दिया फाइल्स के अंदर यह सब एक ही
चीज है ठीक है लेकिन लेकिन लेकिन लेकिन
मैं आपको जैसे ही बता रहा था कि हां यह जो
इटर एफ है और यह जो एफ है दोनों सेम चीज
फाइल के लिए लिस्ट के लिए नहीं है तो
लिस्ट के अंदर क्या होता है जैसे सपोज
करिए हम एक और लिस्ट लेते हैं माय न्यू
लिस्ट ठीक है जी और माय न्यू लिस्ट के
अंदर मैंने वैल्यूज डाली बोला कि 1 2 3 4
दे दो थ्री ही दे दो चलो ठीक है अब हम
क्या कर रहे थे एक्चुअली में मैं बोल रहा
था कि मुझे चाहिए एक इटर और इस इटर के
अंदर वैल्यूज डाल रहे थे
माय न्यू लिस्ट और इसी को तो हम होल्ड करा
रहे थे आई के अंदर यही तो कर रहे थे लेकिन
क्या यह
चीज एगजैक्टली इक्वल है अ इज हमने क्या
पूछा था अभी फाइल के अंदर एफ में क्योंकि
उसी का पूरा रेफरेंस ले रहे थे लिस्ट का
रेफरेंस आपने कहां पे लिया है माइ लिस्ट
के अंदर
इज माय न्यू लिस्ट क्या सेम है नहीं तो
इससे हमारा यह प्रूफ होता है छोटी सी बात
से कि फाइल को जब आप एक वेरिएबल के अंदर
स्टोर लेते हो उसका रेफरेंस लेते हो तो वह
अपने आप में एक इटरेटेड ऑब्जेक्ट है लेकिन
लिस्ट का अगर आपने किसी मेमोरी रेफरेंस
में उसका नाम दिया है वह उसका इटरेटेड
ऑब्जेक्ट नहीं है वो सिर्फ उस एक्चुअल
ऑब्जेक्ट का रेफरेंस है फाइल के केस में
डिफरेंस है इसीलिए अक्सर लोग फाइल
हैंडलिंग में पाइथन के अंदर फेल होते हैं
क्योंकि उनको यह सब बेसिक्स नहीं पता है
उनको तो पता है लाइब्रेरी लो ऑडियो दे दो
हम इंपोर्ट ऑडियो करते तो ऑडियो आ जाता है
अरे इस तरह से सीखो ग कैसे काम चलेगा
अच्छा लेकिन क्या है अब और भी चीजें आप कर
सकते हो इसके अंदर अब तो सारा बेसिक आपको
आई थिंक आ ही जाएगा किस तरह से अच्छा एक
चीज और ध्यान रखना फाइल और लिस्ट पर तो
हमने बात कर ली लेकिन बहुत सारी और भी चीज
हैं जो इटरेटेड बल है पता नहीं क्यों मैं
तो
इटरेटेड नहीं है वो इटरेबल होना चाहिए था
बट सो सॉरी अब है तो है क्या कर सकते हैं
ठीक है डिक्शनरी भी होती है डिक्शनरी भी
इटरेट बल्स है जैसे फॉर एग्जांपल हमने
सपोज करो ए ले लिया और ए की वैल्यू वन है
और क्या लोगे बी ले लो और और बी की वैल्यू
टू दे दो और भी इस तरह से तो जो डिक्शनरी
है वो भी अपने आप में
इटरेटेड लगाते हो एक छोटा सा लूप आपको लगा
देते हैं फॉर की ही आती है हमेशा लूप के
अंदर इन अ आपको बताया था याद हो तो डी डॉट
कीज लिखना पड़ता है ऐसे नहीं आती है आप की
सारी डिक्शनरी वरना तो फिर की वैल्यू
पेयर्स वगैरह काफी कुछ काम हो जाता है बट
अभी के लिए इतना ठीक है कि हम इसको प्रिंट
भी करवा सकते हैं तो आप जैसे प्रिंट करवाओ
की को तो यह लीजिए सारी कीज ए और बी
प्रिंट हो जाती है अब इंटरेस्टिंग बात यही
काम अगर मैनुअली करना हो तो हां जी कर
सकते हो इसमें कोई दिक्कत नहीं है यह जो
इटर है आपके पास में यह है मैनुअल इटरेशन
इसके अंदर अगर आपने डी दे दिया और वो
ऑब्जेक्ट एक्चुअली में इटरेटेड है तो आपके
पास रेफरेंस आ जाएगा उस रेफरेंस को आप जिस
भी चाहे वैल्यू में होल्ड कर सकते हो अब
जैसे ही मैं i को प्रिंट कराता हूं तो
मेरे पास एक मेमोरी रेफरेंस आ गया है कि
यहां से अब इटरेशन आपका स्टार्ट होगा अगर
यह इटरेटेड होगा तो इसके पास ऑप्शन होगा अ
वही सेम i डॉट अंडर अंडर अगर आपको ये
ज्यादा लग रहा है ना आड तो जैसे इटर है ना
वैसे नेक्स्ट भी है हां जी छोटा सा हैक है
हैक तो क्या है बस अब तो प्रॉपर्ली यूज
होता है तो नेक्स्ट इस तरह से भी यूज कर
सकते हो ज्यादातर आपको लोग इंटरव्यूज में
और उसमें अंडरस्कोर अंडरस्कोर नेक्स्ट इसी
तरह से करते नजर आएंगे बट दोनों एक ही बात
है इंटरनली सेम ही काम होता है ये लीजिए
नेक्स्ट ए नेक्स्ट बी अब यह इंटरेस्टिंग
बात है अब क्या होगा स्टॉप इटरेशन यह
हमारा एक्सेप्शन रेज हो गया तो जितनी भी
चीजें जो पार्शल या कैसे भी इटरेट हो सकती
है वहां पर इसी तरह के काम होते हैं और
सारा का सारा इसी तरह से आता है अच्छा एक
चीज और फाइनली हम इस पे भी इसको क्यों
छोड़ दे जब इतना काम किया है तो आपको याद
है हमने बात करी थोड़ी सी रेंज के अंदर
सपोज करिए रेंज फाइव तो क्या आता है हम इस
तरह से लिखा हुआ आता है ठीक है जी अगर मैं
इसको एक रेफरेंस में होल्ड कर लूं r तो r
में क्या आएगा r में भी एगजैक्टली सेम आता
है क्या रेंज इ ट्रेट बल होती है अभी तो
देखा कई जगह यूज भी करा होती है तो अगर ये
ट्रेट बल होती है है तो क्या मैं इसमें यह
कर सकता हूं इटर और आर देखिए कांसेप्ट अगर
है तो सब जगह अप्लाई होगा तो टेक्निकली तो
होना चाहिए इसका रेफरेंस ले लें अब ठीक है
जी i के अंदर रेफरेंस चेंज कर देते हैं ये
लीजिए i के अंदर आ गया रेफरेंस अब मैं
यहां पे नेक्स्ट थोड़ा सा इजी लगता है
मुझे नेक्स्ट इस तरह से तो ये लीजिए अब
हमारे पास आ गया ये
i देखिए रो से स्टार्ट हुआ 1 2 3 4 5 हो
फाइव पे आते ही तो स्टॉप इटरेशन एक्सेप्शन
क्योंकि रेंज इंक्लूसिव नहीं होती है तो
जब भी आपको लगे ना क्या चीज ट्रीटेबल है
नहीं है तो इस तरह से आप काम कर सकते हैं
और आपको ऐसे-ऐसे रेफरेंस मिल जाएगा ठीक है
तो बस आज के लिए तो इतना ही करते हैं आई
थिंक आपको काफी समझ में आ गया होगा अब कि
हां किस तरह से इटरेशन होता है कैसे
बिहाइंड द सीम काम करते हैं नेक्स्ट का
क्या रोल है पाइथन बड़ी इंटरेस्टिंग
लैंग्वेज है इनफैक्ट कोई भी लैंग्वेज
इंटरेस्टिंग तभी होती है जब आपको बिहाइंड
द सीन पता लगता है कि अच्छा ये लैंग्वेज
इस तरह से काम कर रही है और असली इंजीनियर
भी तभी बनते हैं उम्मीद करता हूं आपको
पाइथन की सीरीज में मजा आ रहा होगा
इंटरेस्ट आ रहा होगा असली इंजीनियर बन रहे
तो बस इतना ही है मिलते हैं आपसे अगले
वीडियो के
अंदर
5.0 / 5 (0 votes)