Behind the scene of loops in python

Chai aur Code
12 Feb 202429:07

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

00:00

😀 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.

05:02

📄 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.

10:04

🔍 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.

15:06

📝 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.

20:08

🔁 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.

25:09

📚 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

Loops are a fundamental concept in programming that allow code to be executed repeatedly based on a condition or until a condition is met. In the script, loops are discussed as a way to perform iterative tasks, such as reading lines from a file or iterating over elements in a list. The video aims to demystify what happens 'behind the scenes' when loops are executed in Python, enhancing the viewer's understanding of how loops function internally.

💡break and continue

These are keywords used within loops to control the flow of iteration. 'break' is used to exit the loop prematurely, while 'continue' skips the current iteration and moves to the next. The script likely discusses these keywords in the context of loop control structures, providing examples of how they can be used to manage loop execution effectively.

💡Comments

Comments in code are notes that developers leave for other developers (or for themselves) to explain the code. They do not affect the execution of the program. The script might encourage the use of comments to clarify the purpose of loops or other complex structures, thereby improving code readability and maintainability.

💡PythonAnywhere

PythonAnywhere is an online integrated development environment (IDE) that allows you to write and execute Python code in a web browser. The script may mention PythonAnywhere as a platform where viewers can practice writing and understanding loops and other Python concepts, as it provides a convenient environment for coding and learning.

💡Files

The term 'files' in the script refers to file handling in Python, which involves opening, reading from, and writing to files. File handling is an important aspect of programming, allowing data to be stored persistently and manipulated as needed. The script likely covers the basics of file operations and how loops can be used to read through a file line by line.

💡Iterators

Iterators are objects that allow you to iterate over all the elements in a collection. In the context of the script, iterators are discussed as a Python feature that enables looping over iterable objects like lists and files. The video aims to clarify how iterators work 'behind the scenes' and their importance in creating efficient loops.

💡Iterable Objects

Iterable objects in Python can be looped over. This includes data structures like lists, strings, and files. The script probably explains that these objects can be used with loops to access each element or line individually, emphasizing the versatility of iterables in Python for different types of data.

💡Underscore and next

In the script, 'underscore' and 'next' likely refer to the built-in Python functions __iter__() and __next__(), which are part of the iterator protocol. These functions are crucial for making an object iterable and for retrieving the next item during iteration, respectively. The video might use these terms to explain the inner workings of iteration in Python.

💡Exception

An exception in Python is an error that occurs during the execution of a program. The script may discuss exceptions, such as 'StopIteration', which is raised when there are no further elements to iterate over. Understanding exceptions is crucial for writing robust loops that can handle unexpected situations gracefully.

💡StopIteration

StopIteration is an exception used to signal the end of an iteration. When a loop iterates over an iterable, if there are no more items to return, StopIteration is raised, and the loop terminates. The script likely uses this term to illustrate how loops know when to stop executing, ensuring that the loop does not run indefinitely.

💡Memory Address

The memory address refers to the location in a computer's memory where a particular piece of data is stored. In the context of the script, discussing memory addresses might be a way to explain how iterators keep track of their position within an iterable. This concept is important for understanding how loops and iterators work at a lower level in Python.

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

play00:00

हां जी कैसे हैं आप सभी स्वागत है आप सभी

play00:03

का चाय और कोड में और हमारी इस सीरीज के

play00:05

अंदर जो कि है सिंपली चाय और पाइथन उम्मीद

play00:10

करता हूं ये सीरीज अभी तक आपको पसंद आ रही

play00:11

होगी अगर पसंद आ रही है तो प्लीज कंजूसी

play00:14

कैसी हो रही है यह

play00:30

के साथ जब सारे मिलके बैठेंगे अच्छा एक

play00:32

बेस्ट चैनल बनाएंगे इंडिया का इसको कोडिंग

play00:34

के लिए तभी तो फिर मजा आएगा उससे कम में

play00:36

तो मजा भी नहीं आएगा इस वीडियो का हमारा

play00:38

छोटा सा एक कमेंट टारगेट भी है प्लीज उसको

play00:41

पूरा करने में हेल्प कीजिएगा मात्र 350

play00:43

कमेंट्स तो चलिए इस वीडियो में अ आपको अगर

play00:46

याद हो लास्ट वीडियो के अंदर हमने लूप्स

play00:48

के बारे में काफी कुछ क्वेश्चंस करे थे

play00:50

क्वेश्चन क्या बेसिकली सिनेरियो थे और उन

play00:52

सिनेरियो के दौरान ही हमने सारे ब्रेक

play00:54

कंटिन्यू जितने भी कीवर्ड्स थे वाइल लूप

play00:56

फॉर लूप सब पढ़ लिए और समझ में भी आ गए

play00:58

हमें ठीक है इस इस वीडियो के अंदर

play01:00

एक्चुअली में मैं कुछ बिहाइंड द सीन

play01:02

बेसिक्स जाना चाह रहा था अ थोड़ा सा हम

play01:04

फाइल्स को भी एक्सप्लोर करेंगे किस तरह से

play01:06

फाइल्स ओपन की जाती है बेसिक फाइल्स

play01:07

python's फाइल और ये सब अ बाइनरी फाइल्स

play01:10

के बारे में अभी डिस्कस नहीं करेंगे उनके

play01:12

लिए थर्ड पार्टी लाइब्रेरीज लगती है उनको

play01:14

भी हम बाद में देखेंगे बट बेसिकली आपको

play01:16

मैं बताना चाह रहा था कि जब आप फाइल्स ओपन

play01:18

करते हो या आप लूप्स चलाते हो तो एक्चुअली

play01:20

में बिहाइंड द सीन pythonanywhere.com

play01:30

जो बाकी लैंग्वेजेस ने नहीं किया है इतने

play01:32

तरीके से बट पाइथन के अंदर थोड़ा सा

play01:34

रिइमेजिन है लूप बिहाइंड द सीन पे फ्रंट प

play01:36

तो आपको वही फॉर लूप वाइल लूप दिखता है

play01:38

लेकिन एक बार बिहाइंड द सीन समझ में आएगा

play01:40

ना तो और अच्छा लगेगा आपको और कॉन्फिडेंस

play01:42

आएगा कि हां एक्चुअली में लैंग्वेज मुझे

play01:44

आती है समझ में आती है तो वही सब आपको

play01:46

बताते हैं पहले एक छोटा सा डायग्राम

play01:48

बनाएंगे आपके साथ में क्योंकि पाइथन का जो

play01:51

लूप का स्ट्रक्चर है सिंटेक्स है वो थोड़ा

play01:53

सा डायग्राम बेसिस पर ही चलता है तो थोड़ा

play01:55

सा हम यहां आ जाते हैं और एक डायग्राम

play01:57

छोटा सा बना लेते हैं अब जो पाइथन के अंदर

play02:00

है ना ये इतना भी कॉम्प्लिकेटेड प्रोसेस

play02:02

नहीं है आपको बेसिकली बताते हैं तो पाइथन

play02:05

ने क्या करा कुछ इटर टूल बनाए या इटरेशन

play02:08

टूल भी आप बोल सकते हो और पहली बात ये जान

play02:09

लीजिए ये जो इटरेशन है ना ये एक फैंसी नाम

play02:12

है लूप्स का ही या फिर चीजों को बार-बार

play02:14

करने का तो मैं इटरेशन बोलूं तो लूप समझ

play02:16

जाइएगा लूप बोलूं तो इटरेशन समझ जाइएगा यह

play02:19

सिर्फ इंग्लिश की कहानी है और कुछ भी नहीं

play02:21

है ज्यादा तो अब सबसे पहली जो जरूरी चीज

play02:24

है ना वो कुछ यह है कि जैसे हम यहां पे

play02:26

आते हैं तो सबसे पहले तो एक टेक्स्ट मैं

play02:28

कर लेता हूं

play02:30

इटरेशन टूल्स अ इटरेशन टूल है कौन से

play02:33

पाइथन में देखिए फॉर लूप आपका एक इटरेशन

play02:36

टूल है कंप्रीहेंशंस जो

play02:40

है

play02:41

कंप्रीहेंशंस और भी है मैप भी है यह सारी

play02:45

चीजें ना अपने आप में एक इटर टूल के अंदर

play02:47

ही आती है तो इसको मैं ब्रैकेट में रख

play02:48

देता हूं यहां पे क्योंकि ये सारे ना

play02:50

टूल्स ही है आपके और कुछ भी नहीं है तो

play02:52

पहला तो हमारे पास यह हुआ कि एक हमारे पास

play02:54

में इटर टूल है और यह हो गया काम अब इटर

play02:58

टूल ही क्यों फॉर लूप तो बेसिकली फॉर एक

play03:01

अपने आप में कीवर्ड होता है जो यह काम

play03:02

करता है नहीं नहीं पाइथन इनको इस तरह से

play03:04

नहीं देखता है पाइथन देखता है कि ये

play03:05

इटरेशन के टूल्स हैं अब इटरेशन के टूल

play03:08

सिर्फ उसी पर काम आ सकते हैं जो कि

play03:10

इटरेटेड हो तो यह एक कांसेप्ट आपको और

play03:13

समझना पड़ेगा यह वैसे तो होता सभी

play03:14

लैंग्वेजेस में है बट कई बार बात नहीं की

play03:17

जाती है इस परे और ज्यादा कुछ होता भी

play03:19

नहीं इतना बात करने के लिए बट आपके पास

play03:21

होते क्या

play03:22

है इटरेटेड

play03:26

ऑब्जेक्ट्स

play03:27

अगर स्पेलिंग सही लिखी तो ठीक है इटरेटेड

play03:32

ठीक है ठीक ही लग रही

play03:34

है एक्चुअली मैं इसको इटरेबल ऑब्जेक्ट्स

play03:37

बोला जाता है वैसे तो ठीक है बट इटरेटेड

play03:40

ऑब्जेक्ट्स बोलो इटरेबल ऑब्जेक्ट्स ठीक है

play03:42

थोड़ा सा इंग्लिश का मुझे भी लग रहा है

play03:44

मुझे जहां तक ध्यान है इन को इटरेटेड नहीं

play03:46

इटरेबल ऑब्जेक्ट्स बोला जाता है सही

play03:48

इंग्लिश में बट ठीक है चलेगा अब ये इटरेबल

play03:51

ऑब्जेक्ट्स होते कौन से हैं देखिए इन

play03:53

ऑब्जेक्ट्स के अंदर आपको दिखेगा कुछ इस

play03:55

तरह के एग्जांपल्स जैसे कि हमारे पास हो

play03:58

गया लिस्ट्स हो गई यह सबसे कॉमन दिखेगा

play04:00

स्ट्रिंग्स भी अपने आप में एक है और एक

play04:02

एग्जांपल मैं यहां जान पूछ के लेना

play04:04

चाहूंगा जो है फाइल फाइल भी एक इटरेबल

play04:07

ऑब्जेक्ट है लेकिन उसका जो इंप्लीमेंटेशन

play04:09

है ना इटर ऑब्जेक्ट्स का वो थोड़ा सा अलग

play04:11

है कंपेयर टू आपकी रेगुलर लिस्ट से लिस्ट

play04:13

पे तो हमने कई बार लूप लगाया एक एरे लिया

play04:15

1 2 3 4 5 वैल्यू डाली फॉर आई इन लिस्ट

play04:18

प्रिंट आई तो ये सब काम तो हमने किया है

play04:21

अच्छा ये तो हो गया बेसिक कि ठीक है आपके

play04:23

पास ये ट्रीटेबल ऑब्जेक्ट है इस तरह से

play04:25

लेकिन अब यहां पे इसको भी हम एक बॉक्स के

play04:28

अंदर डाल देते हैं ठीक है आप का भी काम हो

play04:30

गया है अब यहां पे एक और चीज आती है जो कि

play04:32

है रिस्पांस जिस रिस्पांस को हम एक्चुअली

play04:35

में अ बोलते हैं अंडर अंडरस्कोर दो

play04:38

अंडरस्कोर है यहां पे अ नेक्स्ट और फिर

play04:40

अंडरस्कोर अंडरस्कोर इसके दो-तीन तरीके और

play04:43

भी हैं अ बताने के कई बार आप इसको एज अ

play04:44

नेक्स्ट और पेंसिस भी लिख लेते हो वो भी

play04:46

मैं आपको बताऊंगा बट यहां पे इसको बोलते

play04:49

हैं रिस्पांस ठीक है इसको मैं अभी नेक्स्ट

play04:51

ही ले लेता हूं यहां पे और इसको भी एक

play04:53

बॉक्स में बंद कर लेता हूं यह बहुत काम

play04:54

आएगा

play04:56

python3 बेसिकली चीजें हैं एक तो आप

play04:59

अंडरस्कोर अंडरस्कोर नेक्स्ट अंडरस्कोर

play05:01

अंडरस्कोर और एक आपका है इटरेबल

play05:04

ऑब्जेक्ट्स जो कि लिस्ट फाइल है जिस पर भी

play05:06

आप लूप लगा रहे हो बेसिकली और एक लूप

play05:08

लगाने का टूल लूप लगाने के कई टूल होते

play05:10

हैं जैसे फॉर हो गया कंप्रीहेंशन भी देखा

play05:12

था वो देखा स्टार्टिंग में हम वैल्यू लिख

play05:14

देते हैं फिर लूप लिखते हैं तो वह भी एक

play05:16

तरह का टूल है

play05:18

और मैप भी आप देखोगे इस तरह से अब होता

play05:21

क्या है स्टेप वन के अंदर क्या होता है

play05:24

सबसे पहले तो यह इटर टूल जो है यह क्वेरी

play05:27

करते हैं इटरेबल ऑब्जेक्ट से कि सबब मुझे

play05:31

आपके ऊपर लूप लगाना है तो वो क्या करता है

play05:34

आपको सबसे पहले यहां पर आपको भेजता है एक

play05:36

इटर ऑब्जेक्ट या आप इटर बोल दीजिए इटर

play05:39

मेथड भेजता है कि देखो मुझे आपके ऊपर एक

play05:41

लूप भेजना है तो उसको हां इंटरनल भीसी नाम

play05:43

से जाना जाता है तो इसने भेजा एक मेथड कि

play05:45

मुझे लगाना है इटरेटेड ऑब्जेक्ट्स पे एक

play05:48

लूप तो एक इटर मेथड यहां पे भेजता है कि

play05:50

क्या मैं लगा सकता हूं तो इसके रिस्पांस

play05:51

में यूजुअली आता है कि हां आप लगा सकते हो

play05:54

लेकिन रिस्पांस में सिर्फ आपके पास ये

play05:55

नहीं आता है कि आप लगा सकते हो आपके पास

play05:57

रिस्पांस में एक्चुअली में नेक्स्ट वैल्यू

play05:59

आती है है तो ये जो इटर ऑब्जेक्ट्स है ना

play06:01

ये आपके पास जाते हैं और एक नेक्स्ट भेजते

play06:03

हैं कि साहब अब आपको मैं एक नेक्स्ट

play06:05

रिटर्न कर रहा हूं अगर आपके पास रिटर्न

play06:08

में नेक्स्ट आता है ये अंडरस्कोर अंडर

play06:10

नेक्स्ट तो आपके पास जो फर्स्ट वैल्यू है

play06:13

क्योंकि देखिए क्या आपने सोचा है कभी कि

play06:15

इस तरह से जब आप एक कोई एरे लेते हैं सपोज

play06:17

करिए हमारा एरे है या लिस्ट है जिसके अंदर

play06:20

आपके पास वैल्यूज है 1 2 3 4 अ तो इसको

play06:23

पता कैसे लगता है कि एक्चुअली में फोर

play06:25

वैल्यू आ गई है ये फोर के बाहर क्यों नहीं

play06:27

जाता है बाउंड्रीज को क्रॉस क्यों नहीं

play06:29

करता है और इसको कैसे पता है फर्स्ट

play06:30

वैल्यू यहीं से स्टार्ट करना है ये यहां

play06:32

से स्टार्ट क्यों नहीं करता है यह सारा जो

play06:34

जितना भी क्वेश्चंस है ना यह क्वेश्चंस के

play06:36

आंसर एक्चुअली में नेक्स्ट में जाते हैं

play06:38

इटरेबल ऑब्जेक्ट्स आपको हमेशा मेमोरी के

play06:40

स्टार्ट लोकेशन पे पॉइंट करता है कभी भी

play06:43

आपको पूरा लिस्ट नहीं देता है वोह आपको

play06:44

पॉइंट करता है यहां से लूपिंग स्टार्ट

play06:46

करनी है क्योंकि यहां से आपको कंटीन्यूअस

play06:48

मेमोरी एलोकेशन मिल रहा है तो जब भी आप

play06:50

इटरेबल ऑब्जेक्ट्स को देखोगे तो आपको एक

play06:52

रिटर्न में एक ऑब्जेक्ट में मेमोरी एड्रेस

play06:54

मिलता है वह आपके स्टार्ट पॉइंट पे होता

play06:56

है प्लस आपको साथ में मिलता है यह नेक्स्ट

play06:58

अब ये नेक्स्ट क्या कर करता है जब तक आपको

play07:00

नेक्स्ट मिल रहा है ना तो जो मेमोरी

play07:02

एड्रेस है वहां पे जो वैल्यू है वो तो आप

play07:04

प्रिंट कर ही दोगे क्योंकि वो तो आ ही रही

play07:05

है आपके पास में लेकिन अगर आपके पास में

play07:07

नेक्स्ट आया इसका मतलब है और भी लूप लगाया

play07:10

जा सकता है आगे और वैल्यू है मेमोरी

play07:12

एड्रेस में और वैल्यूज एजिस्ट करती है तो

play07:15

ये जब वैल्यू आती है आपके पास में तो फिर

play07:17

ये जो इटर टूल है ना यह क्या करते हैं ये

play07:19

इटर टूल के पास जैसे ही नेक्स्ट आता है तो

play07:21

हम क्या करते हैं इसको बार-बार से नेक्स्ट

play07:23

नेक्स्ट नेक्स्ट करवाते जाते हैं तो आपके

play07:25

पास कुछ इस तरह से होता है कि अभी मैं

play07:26

करके भी दिखाऊंगा सारा प्रैक्टिकल चिंता

play07:28

मत करो नेक्स्ट अब ये नेक्स्ट पैरेंस से

play07:31

लिखो चाहे अंडरस्कोर अंडरस्कोर नेक्स्ट

play07:32

लिखो एक ही बात है तो आप ये नेक्स्ट

play07:34

नेक्स्ट नेक्स्ट करते रहते हो तो जितनी

play07:35

बार नेक्स्ट करते हो उतनी बार वैल्यू आपकी

play07:37

प्रिंट होती जाती है तो ये कुछ इस तरह से

play07:39

नेक्स्ट नेक्स्ट तो होता जाता है अब फाइनल

play07:42

जब नेक्स्ट आता है जब आप फोर पे पहुंच गए

play07:44

हो तब आपके पास एक एक्सेप्शन रेज होता है

play07:46

स्टॉप इटरेशन एक्सेप्शन तो वो जैसे

play07:48

एक्सेप्शन रेज होता है तब पता लग जाता है

play07:50

कि देखो साहब एक्सेप्शन आ गया है अब आगे

play07:52

और वैल्यूज नहीं है तो आगे नहीं जाएंगे हम

play07:55

यह पूरी कहानी होती है बिहाइंड द सीन तो

play07:57

तीन इसके अंदर मेजर किरदार हैं तीन हीरोज

play08:00

बोल सकते हैं कि एक तो आपका इटर टूल होगा

play08:02

ही होगा फॉर हो सकता है कॉम्प्रिंट हो

play08:04

सकते हैं कुछ भी हो सकते हैं और

play08:28

pythonanywhere.com अब इस थ्योरी को हमें

play08:30

प्रैक्टिकल में भी तो उतारना पड़ेगा

play08:32

क्योंकि एक्चुअली में तो आपको समझ में तो

play08:35

सारा अच्छे से ज्यादा तो वहीं पे आएगा ठीक

play08:38

है तो अब हम क्या करते हैं थोड़ा सा बेसिक

play08:41

प जाते हैं लेकिन आपको मैं एक चीज और बता

play08:43

दूं थोड़ा सा एक्सेप्शन होता है फाइल्स के

play08:45

अंदर तो फाइल से भी भेड़ लेते हैं इतना

play08:48

सोचना समझना क्यों चलिए तो अब हम चलते हैं

play08:50

यह तो हो गया हमारा काम बेसिक फाइल को

play08:52

थोड़ा सा अलग ट्रीट करना है बस और कुछ भी

play08:54

नहीं है हम यह सारा का सारा काम करेंगे

play08:56

टर्मिनल पे क्योंकि वहां पे इजीली आपको सम

play08:59

समझ में आएगा अच्छा सिर्फ टर्मिनल यहां

play09:00

नहीं ओपन करना है मुझे मैं एक नया फोल्डर

play09:04

ही बना लेते हैं और इसको बोल देते हैं

play09:08

04

play09:10

अंडरस्कोर इटरेशन इटरेशन टूल्स बोल लीजिए

play09:14

इटरेशन टूल्स बोल लेते हैं और इसके अंदर

play09:17

मुझे एक नई फाइल बनानी ही पड़ेगी क्योंकि

play09:19

वरना स्क्रिप्ट ओपन क्या करेंगे तो इसको

play09:21

बोल देते हैं स्क्रिप्ट या चाय बोल देते

play09:24

हैं ठीक है यड पवा ठीक है काफी देर हो गई

play09:27

चाय से कुछ काम भी नहीं किया यहां पर आप

play09:29

कुछ भी अपना कोड लिख दीजिए जैसे आपको

play09:31

इंपोर्ट करना है टाइम क्यों करना है पता

play09:34

नहीं बट कर लीजिए उसके बाद आप कुछ प्रिंट

play09:37

करवा दीजिए प्रिंट करवा दीजिए चाय इज हियर

play09:42

ठीक है और इसके बाद सपोज करिए आपको कुछ

play09:45

वेरिएबल चाहिए ठीक है यूजर नेम आपने

play09:47

वेरिएबल लिया और इसको मैंने लिख दिया

play09:49

हितेश डायरेक्ट तो नहीं लिख सकता ये लीजिए

play09:53

और फिर इसको भी प्रिंट करवा दीजिए क्यों

play09:55

करवाना है वो कुछ नहीं पता बस एक फाइल

play09:56

चाहिए थी क्योंकि टेक्स्ट फाइल में काम

play09:59

काम करोगे तो इतना मजा नहीं आता है तो यह

play10:01

लीजिए यह आपकी एक बेसिक चार लाइन का कोड

play10:04

है और हम इस कोड को काम में लेना चाहते

play10:06

हैं अब मैं इस फाइल को क्लोज कर देता हूं

play10:08

काम इसका कुछ नहीं था राट क्लिक करिए

play10:10

इटरेशन टूल पे और ओपन एंड इंटीग्रेटेड

play10:12

टर्मिनल क्लिक करिए अब हुआ इससे क्या कि

play10:15

जैसे ही आप एलएस करोगे तो आपको ये फाइल

play10:17

दिख जाएगी मैं नहीं चाहता था कि लॉन्ग पाथ

play10:18

दूं मैं उसी फाइल के अंदर उसी डायरेक्टरी

play10:21

में रहना चाहता हूं वहीं पर ओपन कर लेता

play10:23

हूं अपने python3 शेल को और अब हम आ गए

play10:25

हैं पाइथन के अंदर ठीक है अब आप सोच रहे

play10:28

होंगे कि फाइल ओपन करना पाइथन में ना कुछ

play10:30

बहुत बड़ा एक काम होता होगा या कुछ इस तरह

play10:33

से होता होगा नहीं नहीं इतना बड़ा कुछ काम

play10:34

नहीं है आपको जब भी फाइल ओपन करनी है आप

play10:37

सीधा ही ओपन करिए यह लीजिए ओपन मेथड पाइथन

play10:40

के अंदर बाय डिफॉल्ट होता है स्ट्रिंग के

play10:42

अंदर आप वैल्यू पास कर दीजिए जो भी आपकी

play10:43

वैल्यू है तो हमारे पासड

play10:59

के पास रेफरेंस हो गया अब आप कई बार

play11:01

देखेंगे जब ये रेफरेंस आपके पास आ गया है

play11:03

तो आपके पास कई मेथड्स हैं अब इस फाइल को

play11:05

रीड करने के लिए तो एक सबसे कॉमन मेथड जो

play11:08

आपको मिलेगा वो मिलेगा एक ये रीड लाइन

play11:10

करके कि आप एक लाइन इसमें से रीड कर दीजिए

play11:14

क्योंकि एक्चुअली में अगर आप फाइल को

play11:15

थोड़ा सा और ब्रॉडली देखोगे तो फाइल के

play11:17

अंदर है क्या मेमोरी में जाने के बाद तो

play11:19

वो लाइंस ही है तो वही एरे जैसा ही काम है

play11:21

कि हर लाइन पे कुछ ना कुछ लिखा हुआ है तो

play11:23

ये रीड लाइन कुछ ना कुछ इसी तरह से काम

play11:25

करता है ये भी अपने आप में एक इटरेटर टूल

play11:27

ही है जो आपको एक-एक लाइन यहां पे रीड

play11:29

करके दे रहा है फर्स्ट इंपोर्ट टाइम किया

play11:31

और वापस से करोगे तो इसने कहा कि प्रिंट

play11:33

चाय इज हियर यही हमने लिखा था उसके बाद

play11:36

आपने फिर किया तो इसने यूजर नेम दिया उसके

play11:38

बाद प्रिंट भी करा लिया लेकिन अब मैं

play11:41

दोबारा से करूंगा तो क्या होगा क्योंकि ये

play11:43

जो चीजें है ना रीड लाइन ये इंप्लीमेंटेड

play11:45

है python2 तो इन्होंने एक्सेप्शन ना बड़े

play11:48

प्यार से हैंडल कर रखा है तो जैसे ही आप

play11:50

करोगे फाइनल आपको ये जो एमटी स्ट्रिंग मिल

play11:52

रही है मतलब अब लाइन ब्रेक हो गया है अब

play11:54

इसके बाद दोबारा करने चाहोगे तो ये हर बार

play11:56

आपको यह देगा क्योंकि एक्सेप्शन रेज हो

play11:58

गया है आप आपकी फाइल कंपलीटली रीड हो चुकी

play12:00

है ठीक है यह तो हमारा बेसिक तरीका था

play12:03

लेकिन अब जो इंटरेस्टिंग बात है ना वो

play12:06

करते हैं अब हम अब हम क्या करते हैं इसको

play12:08

वापस से रन कराते हैं क्योंकि एक्चुअली

play12:10

में ना मुझे वापस से फाइल रीड करनी है

play12:12

अच्छा अभी मैं वापस से क्यों चला रहा हूं

play12:14

क्योंकि अभी जो इस फाइल के अंदर होगा ना

play12:16

अब वापस से आपकी फाइल लोड हो गई है इसके

play12:18

अंदर इस वेरिएबल के अंदर अब हमने अभी तक

play12:20

तो देखा था कि इसके पास मेथड है बट मैंने

play12:22

आपको बताया कि एक जो मेथड है अंडरस्कोर

play12:25

अंडरस्कोर नेक्स्ट अंडरस्कोर अंडरस्कोर ये

play12:28

भी अवेलेबल है ये कोर सिंटेक्स है जो कि

play12:31

इटरेटेड बनाता है चीज को तो इसको अगर आप

play12:33

पैरेंस के साथ जैसे ही रन करोगे तो आउटपुट

play12:37

आपके पास एगजैक्टली सेम आया लेकिन यह रॉ

play12:39

तरीका है जैसा

play12:54

python2 में है ना वो क्रशिंग वाला पार्ट

play12:56

नहीं होता कैसे बताता हूं इंपोर्ट टाइम तो

play12:58

तो आ गया प्रिंट चाय भी आ गया चाय इज हियर

play13:01

नेक्स्ट आपको भी पता है यूजर नेम लिया था

play13:03

और इस यूजर नेम को प्रिंट करवाया था इसके

play13:05

बाद क्या जब आप रीड लाइन मेथड यूज़ कर रहे

play13:07

थे जो आपको अक्सर सारे ट्यूटोरियल्स में

play13:09

सारे टीचर्स सब पढ़ाते हुए नजर आएंगे

play13:11

लेकिन रॉ तरीके में क्या वो रीड लाइन भी

play13:13

तो कैसे ना कैसे डिफाइन हुआ होगा किसी ने

play13:15

कोडर ने कोड लिखा होगा तो यहां पे जब आप

play13:17

करते हो तो देखो अब हमारे पास में एक

play13:19

एक्सेप्शन रेज हुआ है स्टॉप इटरेशन तो रीड

play13:21

लाइन कहीं ना कहीं बिहाइंड द सीन इस

play13:24

एक्सेप्शन को अच्छे से हैंडल करके आपको

play13:26

रिटर्न कर रहा है एमटी स्ट्र

play13:29

ठीक है यही बेसिक काम है इसी तरह से काम

play13:32

होता है वैसे बाय द वे ये तो हमने एक-एक

play13:33

करके कराया आप चाहो तो इसको लूप में भी कर

play13:35

सकते थे लूप के अंदर भी कोई ज्यादा ऐसे

play13:37

प्रॉब्लम नहीं है फाइल्स ओपन करके रीड

play13:39

करने में तो आप बहुत आसानी से कर सकते हो

play13:41

क्योंकि ट्रेबल है वो और ट्रेबल ऑब्जेक्ट

play13:43

है फाइल अपने आप में तो आप सारे इटरेशन के

play13:45

टूल्स यूज कर सकते हो अभी तो हमने रीड

play13:47

लाइन एक टूल यूज करा आप चाहो तो और भी कर

play13:49

सकते हो जैसे मैं बोल दूं फॉर लाइन

play13:51

वेरिएबल का नाम है कुछ भी रख सकते हो इन

play13:53

अब ओपन ही तो करना है ओपन करते तो इटरेबल

play13:55

बन जाता है वो तो ओपन करके आप उस

play13:57

स्क्रिप्ट को ले लीजिए

play13:59

स्क्रिप्ट है हमारी चाय ड पवा यह लीजिए

play14:03

चाय आ गई अब यहां पर आपको कई लोग ना इसके

play14:06

बाद आपको दिखेंगे डॉट रीड लाइंस एक यह भी

play14:10

मेथड होता था पुराना रीड लाइंस अब आपको

play14:12

कोई लाइन नहीं लाइंस यह मेथड अब आपको कोई

play14:15

यूज करता हुआ नजर नहीं आएगा क्योंकि यह

play14:17

मेथड एक्चुअली में मेमोरी पर थोड़ा सा

play14:19

भारी पड़ता है तो इसीलिए अभी की डेट में

play14:22

आपको सिर्फ यह ओपन इस तरह से ही सारे

play14:23

प्रोजेक्ट मिलेंगे बट जस्ट फॉर फन आपको

play14:25

बता दिया कि हां रीड लाइंस भी यूज करते

play14:27

हैं कई लोग य आपने कर लिया अब देखिए अब

play14:29

आपको करना क्या है अब आपको प्रिंट ही

play14:31

करानी है लाइन बस और कुछ भी नहीं करना है

play14:33

तो यहां पर मैं टैब करके करता हूं और इसको

play14:35

प्रिंट करा दीजिए पूरी

play14:37

लाइन अच्छा अब सबसे इंटरेस्टिंग बात हम कि

play14:42

ये लाइन तो हम प्रिंट करा देंगे चलिए एक

play14:44

बार देखते हैं होता क्या है ये लीजिए इसको

play14:47

कैसे पता लगा कि डबल कोट्स जब आए एमटी

play14:50

स्ट्रिंग आ तब मुझे खत्म करना है इस लूप

play14:53

को कभी सोचा इस बारे में हां जी क्योंकि

play14:56

यह सब है क्या यह सब इटरेटेड टू टूल्स हैं

play14:59

इन टूल्स के अंदर ऑलरेडी यह प्रोग्रामिंग

play15:01

की गई है कि किस तरह से फाइल को रीड करना

play15:03

है किस तरह से एमटी आए तोब आपको हटना है

play15:06

यह सारा काम इसके अंदर दे रखा है कि कैसे

play15:08

आपको काम करना है अब सबके बीच में एक-एक

play15:10

लाइन इसलिए आ गई है क्योंकि वहां पे जो

play15:12

स्लैश एन है ना वो प्रॉपर्ली रीड नहीं

play15:13

होता है प्रिंट इसके अंदर तो आप चाहो तो

play15:16

इसको कुछ इस तरह से लिख के और यहां पे हम

play15:18

प्रिंट लाइन ये है तो एंड और यहां पे

play15:20

डिफाइन कर सकते हैं कि यार एंड को है ना

play15:22

आप अ एंटर से मत करना इसको हम जस्ट डबल

play15:26

कोट से कर देते हैं तो अपना काम इससे भी

play15:28

हो जाता तो बेसिक है ये ठीक है जी यह तो

play15:31

हो गया हमारा बेसिक कि ठीक है इस तरह से

play15:33

लाइंस रीड होती है आप यह सारा काम कर सकते

play15:35

हो और वैसे तो वाइल लूप से भी कर सकते हो

play15:38

वो भी चाहो तो मैं करके दिखा दूंगा लाइन

play15:41

अच्छा वाइल लूप के अंदर थोड़ा सा एक

play15:42

सिंटेक्स चेंज होगा करें चलिए लव वाइ लूप

play15:45

भी कर लेते हैं चलिए आप बोल ही रहे तो तो

play15:48

देखिए हमें पहले तो इस तरह से हम ओपन कर

play15:50

रहे थे तो हमें एक रेफरेंस चाहिए यह रहा

play15:53

कि ओपन करा इस फाइल को वाइल लूप से इसलिए

play15:57

करते है क्योंकि वाइल लूप के अंदर ना फॉर

play15:58

की तरह वो सिंटेक्स नहीं आता है जैसे फॉर

play16:00

लाइन इन किसके अंदर वाइल लूप में तो ट्रू

play16:03

फॉल्स ही जाता है सीधा तो वाइल आपने लिखा

play16:05

और ट्रू तो तभी तो आप वाइल लूप के अंदर

play16:07

जाओगे तो ये सिंटेक्स थोड़ा सा चेंज हो

play16:09

जाता है अब इसके अंदर क्या करना है कि

play16:11

आपको एक-एक करके लाइन रीड करनी पड़ेगी तो

play16:13

हमारी जो लाइन है उसको रीड करना पड़ेगा अब

play16:16

यहां पे आपके पास ज्यादा ऑप्शन नहीं है तो

play16:18

f जो भी आपने लिया है डॉट रीड लाइन तो ये

play16:21

हमारा मेथड हो गया ये लीजिए रीड लाइन से

play16:24

ठीक है जी अब नेक्स्ट क्या करना पड़ेगा कि

play16:26

अगर लाइन है ही नहीं तो ब्रेक कर दो लूप

play16:28

को यही तो हमने पढ़ा था कि जब भी आपको लूप

play16:30

से बाहर आना है ब्रेक कर दो उसको तो यहां

play16:33

पर क्या है इफ नॉट लाइन है ये नॉट भी अपने

play16:35

आप में कीवर्ड है इसके बारे में भी हम बात

play16:37

करेंगे आगे जाके बस नॉट लाइन का मतलब है

play16:40

मैं वो भी बता दूंगा नॉट लाइन मतलब जब कुछ

play16:42

हो ही नहीं आपके पास में तो हम क्या

play16:44

करेंगे इफ नॉट

play16:45

लाइन तो यही एक ही लाइन में लिख लेते हैं

play16:48

इसको तो ब्रेक और वरना क्या करो अगर लाइन

play16:51

के अंदर कुछ है तो हम प्रिंट करा देंगे उस

play16:54

लाइन को ये लीजिए प्रिंट करा देते हैं

play16:57

लाइन और एंड को हम यह लीजिए सिंगल कोड्स

play17:01

में रख देते हैं ठीक है तो देखो वही एक्ट

play17:04

आउटपुट आया है लेकिन हमारा लाइन ब्रेक हो

play17:06

गया जब लाइन के अंदर कुछ नहीं है एमटी

play17:08

स्ट्रिंग्स है तो उसको हम ट्रीट कर देते

play17:10

हैं ओके एक छोटी सी चीज और बताना चाहूंगा

play17:13

मैं यहां पर आपको सपोज

play17:15

करिए टेस्ट

play17:18

है अब इस टेस्ट के अंदर हम कुछ वेरिएबल

play17:21

में वैल्यू डालते

play17:23

हैं तो सपोज करिए इसमें मैं वैल्यू डालता

play17:27

हूं

play17:30

अ ये लीजिए हितेश अब यहां पर आप इसको

play17:33

टेस्ट करके देखिएगा

play17:35

कि नॉट हितेश इन लॉ इफ नॉट इन टेस्ट या

play17:39

फिर वो जो अभी हमने सिंटेक्स लिखा इफ नॉट

play17:41

हितेश तो क्या होता है इफ हितेश होता है

play17:44

तो क्या होता है जैसे सपोज करिए आप लिख

play17:45

दीजिए इफ नॉट टेस्ट तो हम यहां पर क्या

play17:50

करेंगे इफ नॉट टेस्ट तो इसको हम प्रिंट

play17:53

करवा लेते

play17:55

हैं और इसको लिख देते हैं चाय

play17:59

यह सिर्फ आपको बेसिक बताने के लिए कैसे हो

play18:01

रहा है एंटर करा अभी आपके पास कुछ भी नहीं

play18:04

आया क्योंकि नॉट टेस्ट वैल्यू पास नहीं

play18:06

हुई अब हम चलते हैं वापस से इसके अंदर हम

play18:09

डाल देते हैं एमटी स्ट्रिंग ठीक है अब हम

play18:12

इसको वापस से कराते हैं इफ नॉट

play18:14

टेस्ट तो प्रिंट चाय तो आपके पास चाय

play18:18

प्रिंट हो गई तो बस इतना सा ही था इसमें

play18:20

कुछ ज्यादा ऐसे कोई बड़ी सोचने वाली बात

play18:21

नहीं है यह सिर्फ टेस्ट करता है कि उसके

play18:23

अंदर कोई वैल्यू है या नहीं और ट्रू और

play18:24

फाल्स आपको रिजल्ट देता

play18:27

है ठीक है यह तो हो गई बात हमारी बेसिक अब

play18:31

वापस से आते हैं हम थोड़ा सा इटरेशन की

play18:32

तरफ कि ठीक है हमने स्क्रिप्ट और इन सब का

play18:35

तो देख लिया कि किस तरह से एक्सेप्शन आते

play18:37

हैं यह मेथड्स आप कैसे कॉल करते हो यह सब

play18:40

भी हमने देख लिया बेसिक बेसिक अब आपको

play18:42

थोड़ा सा और लेके चलते हैं इटरेशन टूल्स

play18:44

की तरफ कि फाइल से तो आपने देख लिया

play18:46

फाइल्स अब आपको समझ में भी आ गया रीड लाइन

play18:48

मेथड है स्टॉप इटरेशन एक्सेप्शन आता है

play18:51

थोड़ा सा अरेज के साथ या हमारे लिस्ट के

play18:54

साथ भी थोड़ा सा खेल लिया जाए अब सपोज

play18:56

करिए अ इसको बोल बोल देते हैं माय लिस्ट

play18:59

जो भी आपका नाम देना है आप दे दीजिए और यह

play19:02

हमारे पास में हमने देखा कि 1 2 3 4 यह

play19:04

लीजिए फोर वैल्यूज दी इसके ऊपर भी तो

play19:07

हमारे इटरेटेड टूल्स हैं जो काम करते

play19:09

होंगे तो क्या यहां पर भी व अंडरस्कोर

play19:11

अंडरस्कोर नेक्स्ट वगैरह वो सब काम में

play19:12

आता है ये इंटरेस्टिंग बात कही आपने तो हम

play19:15

क्या करते हैं एक्चुअली में अब आपको मैं

play19:17

इटर टूल्स ही बताता हूं सीधा आपको ध्यान

play19:20

हो तो मैंने आपको दिखाया था कि इटर टूल्स

play19:22

जो होते हैं अच्छा फाइल के अंदर तो हमने

play19:24

कोई इटर टूल प बात नहीं करी उस परे भी

play19:26

करेंगे क्योंकि फाइल का खुद का इटर टूल

play19:28

होता है ये पाइथन के अंदर बाय डिफॉल्ट है

play19:30

जैसे आपने कहा ना f इक्वल्स ओपन फाइल नेम

play19:33

तो उसका इटर टूल खुद आता है लेकिन लिस्ट

play19:35

वगैरह या बाकी किसी के साथ नहीं आता है

play19:37

फाइल अपने आप में एक इंटरेस्टिंग चीज है

play19:39

बाकी किसी के साथ नहीं आता है तो आप क्या

play19:42

कर सकते हो कहीं पे भी बोल सकते हो कि मैं

play19:44

इटर हां जी अपने आप में एक कीवर्ड है और

play19:47

अपने आप में एक मेथड है आप इसके बारे में

play19:49

और डिटेल में भी पढ़ सकते हो तो इसके अंदर

play19:51

आप कोई भी इटरेटेड ऑब्जेक्ट दे सकते हो

play19:54

इटरेबल ऑब्जेक्ट्स ज्यादा ठीक होगा

play19:56

इटरेटेड ऑब्जेक्ट्स जो जो भी आप कहे तो यह

play19:59

माय लिस्ट मैंने यहां दे दिया अब इस पूरे

play20:02

का रेफरेंस मैं ना अपने किसी वेरिएबल में

play20:04

होल्ड कर सकता हूं पाइथन इसीलिए ज्यादा

play20:05

जानी जाती है सपोज करिए मैं इसको आई ही

play20:07

बोल देता हूं कैपिटल आई कि आई के अंदर अब

play20:10

हमारा पूरा इटर माय लिस्ट है पर आई के

play20:12

अंदर एक्चुअली में है क्या कुछ भी नहीं है

play20:14

इसने बोला कि मैं हूं एक लिस्ट इटरेटर जो

play20:18

कि पॉइंट कर रहा हूं ऑब्जेक्ट एक्ट इस

play20:20

मेमोरी लोकेशन पे तो हमने जो ये लिस्ट

play20:22

बनाई ना तो वहां पर मेमोरी लोकेशन पर अब

play20:25

आप पॉइंट कर रहे हो ठीक है तो यही तो हमने

play20:27

देख अभी एग्जांपल के अंदर कि आपको मिलता

play20:29

क्या है जैसे आप इसको इटर ऑब्जेक्ट के

play20:32

लेते हो तो यहां पे तो आपके पास जो इटर

play20:33

टूल है जो भी इटर टूल आप यूज कर रहे हो

play20:35

फॉर यूज कर रहे हो या हमने मैनुअल यहां पर

play20:37

यूज कर लिया है तो उसके अंदर आपको मिलेगा

play20:39

क्या उस ऑब्जेक्ट का फर्स्ट रेफरेंस

play20:41

मेमोरी का स्टार्टिंग पॉइंट अब यह क्योंकि

play20:44

आई आपके पास आ ही गया है ठीक है तो आपको

play20:47

पता ही है कि अगर वैल्यूज होगी तो वहां पर

play20:50

मैं क्या बोल सकता हूं डॉट अंडर अंडरस्कोर

play20:52

नेक्स्ट अंडरस्कोर अंडरस्कोर और इस तरह से

play20:55

प्रिंट करवा सकता हूं अब क्योंकि अभी आपका

play20:58

मेमोरी लोकेशन फर्स्ट पे है वहां पे तो

play21:01

आपका वन आ गया लेकिन अब i के अंदर वैल्यू

play21:03

क्या है तो अब आप देखोगे i के अंदर वैल्यू

play21:05

तो एगजैक्टली सेम है तो ऐसा नहीं है कि वो

play21:08

मेमोरी रेफरेंस पे आप वहां आ गए तो मेमोरी

play21:10

रेफरेंस भी चेंज करता जाता है ये सारे काम

play21:12

इंटरनली नेक्स्ट कर रहा है कि मैं तो

play21:14

फर्स्ट पे ही पॉइंट करूंगा लेकिन अभी

play21:16

इंटरनली एक पॉइंटर है जिसको मैं रख रहा

play21:18

हूं वो फर्स्ट उसका हो चुका है अब अब वो

play21:20

सेकंड पे अपने आप जाएगा तो ये ऐसा नहीं है

play21:21

कि मेमोरी रेफरेंस चेंज होता है मेमोरी

play21:23

रेफरेंस से जो लिस्ट इटरेटर है वो हमेशा

play21:25

स्टार्टिंग पे ही पॉइंट करेगा अ हां ये

play21:28

इंटरव्यूज में पूछा जाता है समझ में आया

play21:30

क्यों बहुत सारे लोग इंटरव्यूज फेल करते

play21:32

हैं पाइथन के हां पूछते हैं ऐसे सवाल आपको

play21:34

आती है ना पाइथन आप कह रहे हो तो ये सब तो

play21:36

पता होना चाहिए ओके अब चलते हैं वापस से

play21:39

आई नेक्स्ट अब किस पे जाएगा टू पे गया

play21:42

थ्री पे गया फोर पे गया अब क्या होगा अब

play21:46

आपको पता है क्या होगा ये एग्जैक्ट पॉइंट

play21:48

पे अब आपको पाइथन का नॉलेज है ठीक है

play21:50

स्टॉप इटरेशन हमारा एक्सेप्शन रेज हो गया

play21:53

मतलब हमने पूरा लिस्ट इटरेट कर लिया है अब

play21:54

आगे और कुछ भी नहीं है तो हमारे जो

play21:56

नेक्स्ट है फर्द और किसी को पॉइंट नहीं कर

play21:58

रहा है अच्छा जी ठीक है यह तो हो गया

play22:00

हमारा

play22:01

बेसिक अब एक चीज आपको बता देते हैं कि

play22:05

वापस से हम आते हैं थोड़ा सा बैक यह सब

play22:07

बताने के लिए कि यह जो इटर ऑब्जेक्ट है

play22:10

अपना फाइल्स के अंदर बाय डिफॉल्ट होता है

play22:12

जैसे कि मैंने लिखा एफ इक्वल्स ओपन करते

play22:15

हैं फाइल को वापस से जो भी उस फाइल के

play22:17

अंदर था चाय डट

play22:21

पवा और ये लीजिए ठीक है जी यह तो हमें आता

play22:25

था इतना बेसिक तो ठीक था अब अब अगर आप सोच

play22:28

रहे हो कि ये जैसे मैंने रेफरेंस लिया था

play22:30

लिस्ट के अंदर भी तो ऐसे ही लिया था सेम

play22:32

कि लिस्ट एक डिक्लेयर करी थी उसको एक

play22:34

वेरिएबल में डाला था बोला था माय लिस्ट और

play22:37

सिंटेक्स क्या था कुछ इस तरह का था आपको

play22:40

याद हो

play22:43

तो ओके हां ये वाला सिंटेक्स था कि अब इटर

play22:47

के अंदर माय लिस्ट डाल दिया और उसका

play22:49

रेफरेंस हमने होल्ड कर लिया लेकिन आपको यह

play22:52

फाइल के अंदर ऐसा करने की जरूरत नहीं है

play22:55

क्योंकि ये जो एफ है ना ये अपने आप

play22:57

बिहाइंड द सीन इस तरह से वर्क कर चुका है

play23:01

यही डिफॉल्ट पाइथन की प्रोग्रामिंग है कि

play23:04

इसी तरह से काम करता है आप चाहो तो इससे

play23:06

पूछ भी सकते हो कि यह जो इटर एफ मैं

play23:09

बनाऊंगा इज एफ तो क्या ये सेम चीज है आपको

play23:12

याद है इससे पूछ रहे थे हम इज करके क्या

play23:14

ये दोनों सेम है हां जी एगजैक्टली सेम है

play23:18

ठीक है आप इससे यह भी पूछ सकते हो कि अगर

play23:21

मैं बोलूंगा वैसे तो एफ से ही पूछ सकते हो

play23:24

आप बट अगर आपको और जाना है जैसे नेक्स्ट

play23:26

है वैसे इसको ऐसे भी पूछा जा सकता डॉट

play23:28

अंडर अंडरस्कोर इटर अंडरस्कोर अंडरस्कोर

play23:33

और यह मेथड जैसे नेक्स्ट था ना वैसे ही

play23:34

सेम है आंसर इसका भी सेम आएगा बट ऐसे अब

play23:38

कोई नहीं पूछता है बट हा आंसर वही ट्रू

play23:39

आएगा दोनों में एक ही बात है यह आपने बोल

play23:42

दिया या फिर आपने यह बोल दिया या फिर आपने

play23:46

यह बोल दिया फाइल्स के अंदर यह सब एक ही

play23:48

चीज है ठीक है लेकिन लेकिन लेकिन लेकिन

play23:52

मैं आपको जैसे ही बता रहा था कि हां यह जो

play23:54

इटर एफ है और यह जो एफ है दोनों सेम चीज

play23:58

फाइल के लिए लिस्ट के लिए नहीं है तो

play24:00

लिस्ट के अंदर क्या होता है जैसे सपोज

play24:01

करिए हम एक और लिस्ट लेते हैं माय न्यू

play24:05

लिस्ट ठीक है जी और माय न्यू लिस्ट के

play24:08

अंदर मैंने वैल्यूज डाली बोला कि 1 2 3 4

play24:11

दे दो थ्री ही दे दो चलो ठीक है अब हम

play24:14

क्या कर रहे थे एक्चुअली में मैं बोल रहा

play24:16

था कि मुझे चाहिए एक इटर और इस इटर के

play24:18

अंदर वैल्यूज डाल रहे थे

play24:21

माय न्यू लिस्ट और इसी को तो हम होल्ड करा

play24:24

रहे थे आई के अंदर यही तो कर रहे थे लेकिन

play24:28

क्या यह

play24:30

चीज एगजैक्टली इक्वल है अ इज हमने क्या

play24:36

पूछा था अभी फाइल के अंदर एफ में क्योंकि

play24:38

उसी का पूरा रेफरेंस ले रहे थे लिस्ट का

play24:41

रेफरेंस आपने कहां पे लिया है माइ लिस्ट

play24:43

के अंदर

play24:44

इज माय न्यू लिस्ट क्या सेम है नहीं तो

play24:49

इससे हमारा यह प्रूफ होता है छोटी सी बात

play24:52

से कि फाइल को जब आप एक वेरिएबल के अंदर

play24:54

स्टोर लेते हो उसका रेफरेंस लेते हो तो वह

play24:57

अपने आप में एक इटरेटेड ऑब्जेक्ट है लेकिन

play25:00

लिस्ट का अगर आपने किसी मेमोरी रेफरेंस

play25:02

में उसका नाम दिया है वह उसका इटरेटेड

play25:05

ऑब्जेक्ट नहीं है वो सिर्फ उस एक्चुअल

play25:07

ऑब्जेक्ट का रेफरेंस है फाइल के केस में

play25:09

डिफरेंस है इसीलिए अक्सर लोग फाइल

play25:11

हैंडलिंग में पाइथन के अंदर फेल होते हैं

play25:13

क्योंकि उनको यह सब बेसिक्स नहीं पता है

play25:15

उनको तो पता है लाइब्रेरी लो ऑडियो दे दो

play25:17

हम इंपोर्ट ऑडियो करते तो ऑडियो आ जाता है

play25:19

अरे इस तरह से सीखो ग कैसे काम चलेगा

play25:22

अच्छा लेकिन क्या है अब और भी चीजें आप कर

play25:25

सकते हो इसके अंदर अब तो सारा बेसिक आपको

play25:28

आई थिंक आ ही जाएगा किस तरह से अच्छा एक

play25:30

चीज और ध्यान रखना फाइल और लिस्ट पर तो

play25:32

हमने बात कर ली लेकिन बहुत सारी और भी चीज

play25:34

हैं जो इटरेटेड बल है पता नहीं क्यों मैं

play25:37

तो

play25:39

इटरेटेड नहीं है वो इटरेबल होना चाहिए था

play25:42

बट सो सॉरी अब है तो है क्या कर सकते हैं

play25:44

ठीक है डिक्शनरी भी होती है डिक्शनरी भी

play25:47

इटरेट बल्स है जैसे फॉर एग्जांपल हमने

play25:50

सपोज करो ए ले लिया और ए की वैल्यू वन है

play25:54

और क्या लोगे बी ले लो और और बी की वैल्यू

play25:58

टू दे दो और भी इस तरह से तो जो डिक्शनरी

play26:00

है वो भी अपने आप में

play26:02

इटरेटेड लगाते हो एक छोटा सा लूप आपको लगा

play26:05

देते हैं फॉर की ही आती है हमेशा लूप के

play26:08

अंदर इन अ आपको बताया था याद हो तो डी डॉट

play26:11

कीज लिखना पड़ता है ऐसे नहीं आती है आप की

play26:14

सारी डिक्शनरी वरना तो फिर की वैल्यू

play26:16

पेयर्स वगैरह काफी कुछ काम हो जाता है बट

play26:18

अभी के लिए इतना ठीक है कि हम इसको प्रिंट

play26:20

भी करवा सकते हैं तो आप जैसे प्रिंट करवाओ

play26:23

की को तो यह लीजिए सारी कीज ए और बी

play26:26

प्रिंट हो जाती है अब इंटरेस्टिंग बात यही

play26:29

काम अगर मैनुअली करना हो तो हां जी कर

play26:31

सकते हो इसमें कोई दिक्कत नहीं है यह जो

play26:33

इटर है आपके पास में यह है मैनुअल इटरेशन

play26:36

इसके अंदर अगर आपने डी दे दिया और वो

play26:38

ऑब्जेक्ट एक्चुअली में इटरेटेड है तो आपके

play26:40

पास रेफरेंस आ जाएगा उस रेफरेंस को आप जिस

play26:43

भी चाहे वैल्यू में होल्ड कर सकते हो अब

play26:45

जैसे ही मैं i को प्रिंट कराता हूं तो

play26:47

मेरे पास एक मेमोरी रेफरेंस आ गया है कि

play26:49

यहां से अब इटरेशन आपका स्टार्ट होगा अगर

play26:51

यह इटरेटेड होगा तो इसके पास ऑप्शन होगा अ

play26:56

वही सेम i डॉट अंडर अंडर अगर आपको ये

play26:59

ज्यादा लग रहा है ना आड तो जैसे इटर है ना

play27:01

वैसे नेक्स्ट भी है हां जी छोटा सा हैक है

play27:04

हैक तो क्या है बस अब तो प्रॉपर्ली यूज

play27:06

होता है तो नेक्स्ट इस तरह से भी यूज कर

play27:07

सकते हो ज्यादातर आपको लोग इंटरव्यूज में

play27:09

और उसमें अंडरस्कोर अंडरस्कोर नेक्स्ट इसी

play27:11

तरह से करते नजर आएंगे बट दोनों एक ही बात

play27:13

है इंटरनली सेम ही काम होता है ये लीजिए

play27:16

नेक्स्ट ए नेक्स्ट बी अब यह इंटरेस्टिंग

play27:19

बात है अब क्या होगा स्टॉप इटरेशन यह

play27:22

हमारा एक्सेप्शन रेज हो गया तो जितनी भी

play27:25

चीजें जो पार्शल या कैसे भी इटरेट हो सकती

play27:28

है वहां पर इसी तरह के काम होते हैं और

play27:30

सारा का सारा इसी तरह से आता है अच्छा एक

play27:32

चीज और फाइनली हम इस पे भी इसको क्यों

play27:34

छोड़ दे जब इतना काम किया है तो आपको याद

play27:36

है हमने बात करी थोड़ी सी रेंज के अंदर

play27:38

सपोज करिए रेंज फाइव तो क्या आता है हम इस

play27:41

तरह से लिखा हुआ आता है ठीक है जी अगर मैं

play27:43

इसको एक रेफरेंस में होल्ड कर लूं r तो r

play27:47

में क्या आएगा r में भी एगजैक्टली सेम आता

play27:49

है क्या रेंज इ ट्रेट बल होती है अभी तो

play27:53

देखा कई जगह यूज भी करा होती है तो अगर ये

play27:56

ट्रेट बल होती है है तो क्या मैं इसमें यह

play27:58

कर सकता हूं इटर और आर देखिए कांसेप्ट अगर

play28:01

है तो सब जगह अप्लाई होगा तो टेक्निकली तो

play28:04

होना चाहिए इसका रेफरेंस ले लें अब ठीक है

play28:06

जी i के अंदर रेफरेंस चेंज कर देते हैं ये

play28:08

लीजिए i के अंदर आ गया रेफरेंस अब मैं

play28:10

यहां पे नेक्स्ट थोड़ा सा इजी लगता है

play28:12

मुझे नेक्स्ट इस तरह से तो ये लीजिए अब

play28:14

हमारे पास आ गया ये

play28:16

i देखिए रो से स्टार्ट हुआ 1 2 3 4 5 हो

play28:22

फाइव पे आते ही तो स्टॉप इटरेशन एक्सेप्शन

play28:25

क्योंकि रेंज इंक्लूसिव नहीं होती है तो

play28:27

जब भी आपको लगे ना क्या चीज ट्रीटेबल है

play28:29

नहीं है तो इस तरह से आप काम कर सकते हैं

play28:31

और आपको ऐसे-ऐसे रेफरेंस मिल जाएगा ठीक है

play28:34

तो बस आज के लिए तो इतना ही करते हैं आई

play28:36

थिंक आपको काफी समझ में आ गया होगा अब कि

play28:39

हां किस तरह से इटरेशन होता है कैसे

play28:40

बिहाइंड द सीम काम करते हैं नेक्स्ट का

play28:42

क्या रोल है पाइथन बड़ी इंटरेस्टिंग

play28:44

लैंग्वेज है इनफैक्ट कोई भी लैंग्वेज

play28:46

इंटरेस्टिंग तभी होती है जब आपको बिहाइंड

play28:48

द सीन पता लगता है कि अच्छा ये लैंग्वेज

play28:49

इस तरह से काम कर रही है और असली इंजीनियर

play28:51

भी तभी बनते हैं उम्मीद करता हूं आपको

play28:53

पाइथन की सीरीज में मजा आ रहा होगा

play28:55

इंटरेस्ट आ रहा होगा असली इंजीनियर बन रहे

play28:58

तो बस इतना ही है मिलते हैं आपसे अगले

play28:59

वीडियो के

play29:05

अंदर

Rate This

5.0 / 5 (0 votes)

相关标签
Python LoopsIteration ToolsFile HandlingCode TutorialUnder the HoodException HandlingMemory AddressIterable ObjectsUnderstand PythonCoding Basics
您是否需要英文摘要?