Important Notice:

Write Mode — w

Write Mode — w

3 views 1 min read

Write Mode — w :-

Write Mode का उपयोग किसी file में नया data लिखने के लिए किया जाता है। यदि file मौजूद नहीं है, तो Python नई file create करता है। यदि file पहले से मौजूद है, तो उसका पुराना content delete हो जाता है।

English:

Write mode is used to write new data into a file. If the file does not exist, Python creates a new file. If the file already exists, its previous content is truncated.

Syntax

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


Example

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

file.write("Welcome to Python")

file.close()

print("Data Written Successfully")

Output:

Data Written Successfully

File Content:

Welcome to Python

 

Important Points

  1. w का अर्थ Write Mode है।

  2. यह file में data लिखने के लिए उपयोग होता है।

  3. File मौजूद नहीं होने पर नई file बनाता है।

  4. Existing file का पुराना content delete कर देता है।

  5. इसे सावधानी से उपयोग करना चाहिए।

Related Notes