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
w का अर्थ Write Mode है।
यह file में data लिखने के लिए उपयोग होता है।
File मौजूद नहीं होने पर नई file बनाता है।
Existing file का पुराना content delete कर देता है।
इसे सावधानी से उपयोग करना चाहिए।