Write and Read Mode — w+ :-
w+ Mode का उपयोग file में data लिखने और उसी file से data पढ़ने दोनों के लिए किया जाता है। यदि file पहले से मौजूद है, तो उसका पुराना content delete हो जाता है। यदि file मौजूद नहीं है, तो नई file create हो जाती है।
English:
The w+ mode is used to open a file for both writing and reading. If the file already exists, its previous content is truncated. If it does not exist, a new file is created.
Syntax
Example
Output:
Hello Python Explanation
w+ से file reading और writing दोनों के लिए open हुई।
write() ने file में text लिखा।
seek(0) ने file position को शुरुआत में लाया।
read() ने लिखा हुआ data पढ़ा।
close() ने file बंद कर दी।
Important Points
Reading और writing दोनों कर सकते हैं।
Existing file का पुराना content delete हो जाता है।
File मौजूद नहीं होने पर नई file बनती है।
Initial file position शुरुआत में होती है।
Data लिखने के बाद पढ़ने के लिए seek(0) का उपयोग किया जा सकता है।