Important Notice:

Read Mode — r

Read Mode — r

3 views 1 min read

Read Mode — r :-

Read Mode का उपयोग किसी existing file से data पढ़ने के लिए किया जाता है। इस mode में file केवल reading के लिए open होती है। यदि file मौजूद नहीं है, तो Python FileNotFoundError देता है।

English:

Read mode is used to open an existing file for reading data. If the file does not exist, Python raises a FileNotFoundError.

Syntax -

file = open("filename.txt", "r")

Example

मान लीजिए student.txt file में निम्न data है:

Name: Rahul
Marks: 85

Python Program:

file = open("student.txt", "r")

data = file.read()

print(data)

file.close()

Output:

Name: Rahul
Marks: 85

Important Points

  1. r का अर्थ Read Mode है।

  2. यह file को केवल पढ़ने के लिए open करता है।

  3. File पहले से मौजूद होनी चाहिए।

  4. यह file के existing data को delete नहीं करता।

  5. यह default file opening mode है।

Related Notes