Back-End Programming Exam  >  Back-End Programming Videos  >  Python Tutorial in Hindi  >  Python tutorial in Hindi 48 : How to read text files

Python tutorial in Hindi 48 : How to read text files Video Lecture | Python Tutorial in Hindi - Back-End Programming

FAQs on Python tutorial in Hindi 48 : How to read text files Video Lecture - Python Tutorial in Hindi - Back-End Programming

1. पाठ फ़ाइलें कैसे पढ़ें जाती हैं?
उत्तर: पायथन में, टेक्स्ट फ़ाइलों को पढ़ने के लिए 'open' फ़ंक्शन का उपयोग किया जाता है। इसके लिए हमें फ़ाइल का नाम और फ़ाइल के पथ की आवश्यकता होती है। उदाहरण के लिए, यदि हम एक फ़ाइल को पढ़ना चाहते हैं जो हमारे करंट वर्किंग डायरेक्टरी में है, तो हम निम्नलिखित कोड का उपयोग कर सकते हैं: ```python file = open("filename.txt", "r") content = file.read() print(content) file.close() ```
2. पाठ फ़ाइलों को पढ़ कर उनमें कितने लाइन होते हैं?
उत्तर: एक टेक्स्ट फ़ाइल में 'readlines' फ़ंक्शन का उपयोग करके हम उसमें कितने भी लाइन होते हैं, उन्हें पढ़ सकते हैं। यह एक सूची में लाइनों को वापस देता है, जिसका प्रत्येक आइटम एक लाइन होता है। निम्नलिखित कोड से हम टेक्स्ट फ़ाइल में कितनी लाइनें हैं वह जान सकते हैं: ```python file = open("filename.txt", "r") lines = file.readlines() num_of_lines = len(lines) print(num_of_lines) file.close() ```
3. क्या हम एक टेक्स्ट फ़ाइल के लिए स्ट्रिंग मेथड का उपयोग कर सकते हैं?
उत्तर: हां, हम एक टेक्स्ट फ़ाइल के लिए स्ट्रिंग मेथड का उपयोग कर सकते हैं। जब हम फ़ाइल को पढ़ते हैं, हमें फ़ाइल का सामग्री को स्ट्रिंग के रूप में प्राप्त करने की आवश्यकता होती है। हम इस स्ट्रिंग के लिए स्ट्रिंग मेथड का उपयोग कर सकते हैं, जैसे कि इस उदाहरण में दिखाया गया है: ```python file = open("filename.txt", "r") content = file.read() print(type(content)) file.close() ``` यहां, हम 'type' फ़ंक्शन का उपयोग करके सामग्री का प्रकार जांचते हैं, जो एक स्ट्रिंग होगा।
4. क्या हम एक टेक्स्ट फ़ाइल को रेडिंग के बाद मॉड बदल सकते हैं?
उत्तर: जी हां, हम एक टेक्स्ट फ़ाइल को रेडिंग के बाद मॉड बदल सकते हैं। जब हम फ़ाइल को खोलते हैं, हमें दूसरी पैरामीटर के रूप में मॉड देनी होती है, जो फ़ाइल को कैसे खोलना है। उदाहरण के लिए, यदि हमें फ़ाइल को पढ़ना है और फिर उसे अपडेट करना है, तो हम निम्नलिखित कोड का उपयोग कर सकते हैं: ```python file = open("filename.txt", "r") content = file.read() file.close() file = open("filename.txt", "w") file.write("New content") file.close() ``` यहां, हमने सबसे पहले फ़ाइल को पढ़ा और उसका सामग्री 'content' में संग्रहीत की। फिर हमने उसी फ़ाइल को लिखने के लिए फिर से खोला, इस बार "w" मॉड में, और नए सामग्री को लिखा।
5. क्या हम एक फ़ाइल को रेडिंग करते समय एक विशेष लाइन को छोड़ सकते हैं?
उत्तर: हां, हम एक फ़ाइल को रेडिंग करते समय एक विशेष लाइन को छोड़ सकते हैं। हम 'readlines' फ़ंक्शन का उपयोग करके सभी लाइनों को पढ़ सकते हैं और फिर उनमें से केवल चयनित लाइनों को छोड़ सकते हैं। निम्नलिखित कोड से हम एक टेक्स्ट फ़ाइल को पढ़ते समय प
Related Searches

Free

,

Previous Year Questions with Solutions

,

shortcuts and tricks

,

Extra Questions

,

Summary

,

past year papers

,

study material

,

Viva Questions

,

Python tutorial in Hindi 48 : How to read text files Video Lecture | Python Tutorial in Hindi - Back-End Programming

,

Exam

,

MCQs

,

Important questions

,

Objective type Questions

,

Python tutorial in Hindi 48 : How to read text files Video Lecture | Python Tutorial in Hindi - Back-End Programming

,

Semester Notes

,

Python tutorial in Hindi 48 : How to read text files Video Lecture | Python Tutorial in Hindi - Back-End Programming

,

Sample Paper

,

practice quizzes

,

ppt

,

video lectures

,

mock tests for examination

,

pdf

;