Types of Files (फाइलों के प्रकार) :-
Data को store करने के तरीके के आधार पर computer files को मुख्य रूप से दो प्रकारों में बाँटा जाता है:
English
Based on how data is represented and stored, files are commonly classified into two main types:
Text Files (टेक्स्ट फाइलें)
Binary Files (बाइनरी फाइलें)
open() file को खोलता है या आवश्यकता होने पर बनाता है।
"student.txt" file का नाम है।
"w" write mode है।
encoding="utf-8" text encoding निर्धारित करता है।
write() file में text लिखता है।
\n नई line शुरू करता है।
close() file को बंद करता है।
इनमें text characters store किए जाते हैं।
इन्हें सामान्य text editor में अक्सर पढ़ा जा सकता है।
Python में text mode default होता है।
Text encoding, जैसे UTF-8, characters को bytes में represent करने के लिए उपयोग होती है।
इनका उपयोग notes, reports और textual records के लिए किया जाता है।
Text data को पढ़ना और समझना आसान होता है।
इन्हें आसानी से edit किया जा सकता है।
Data को विभिन्न programs के बीच साझा किया जा सकता है।
कई text formats सरल और portable होते हैं।
हर प्रकार के data के लिए text format उपयुक्त नहीं होता।
Text में save करने पर कुछ data का original binary representation सुरक्षित नहीं रहता।
बड़े या जटिल media data के लिए specialized formats अधिक उपयुक्त होते हैं।
Image files: .jpg, .png
Audio files: .mp3, .wav
Video files: .mp4, .avi
Executable files: .exe
कई document formats: .pdf
"wb" binary write mode है।
b"Hello" bytes object है।
write() bytes को file में लिखता है।
यदि file पहले से मौजूद है, तो wb mode उसकी पुरानी सामग्री को मिटाकर नया data लिखना शुरू करता है।
Data bytes के रूप में पढ़ा और लिखा जाता है।
Binary mode में Python text encoding और decoding अपने-आप लागू नहीं करता।
इनका उपयोग images, audio, video और अन्य binary formats के लिए होता है।
Data को सही तरह समझने के लिए संबंधित file format की जानकारी आवश्यक हो सकती है।
Media और अन्य binary data को उनके निर्धारित format में संभाला जा सकता है।
Binary mode में bytes को बिना text decoding के पढ़ा या लिखा जा सकता है।
यह images, audio, video और structured binary data के लिए उपयोगी है।
Binary mode में bytes का उपयोग होता है, जबकि Text mode में strings (str) को पढ़ा और लिखा जाता है।
Binary mode uses bytes, whereas text mode reads and writes strings (str).
UTF-8 in Python - (Unicode Transformation Format – 8-bit)
UTF-8 एक character encoding है, जिसका उपयोग text को computer में store करने और पढ़ने के लिए किया जाता है। यह English, Hindi और अन्य languages के characters को represent कर सकता है।
In English-
UTF-8 is a character encoding used to store and read text on a computer. It can represent characters from English, Hindi, and other languages.
Example in Pythonइस program में:
open() — File को खोलता है।
encoding="utf-8" — Text की encoding UTF-8 निर्धारित करता है।
file.write() — File में text लिखता है।
"Hello नमस्ते" — English और Hindi दोनों text हैं।
Output in data.txt:
Hindi और English text को सही तरीके से store करने के लिए।
अलग-अलग languages के characters को support करने के लिए।
Text में encoding से जुड़ी समस्याओं को कम करने के लिए।
Exam Point: UTF-8 stands for Unicode Transformation Format – 8-bit.