Create Mode — x :-
Create Mode का उपयोग केवल नई file create करने के लिए किया जाता है। यदि उसी नाम की file पहले से मौजूद है, तो Python FileExistsError देता है।
English:
Create mode is used to create a new file exclusively. If a file with the same name already exists, Python raises a FileExistsError.
Syntax -
file = open("filename.txt", "x")
Example
file = open("newfile.txt", "x")
file.write("This is a new file")
file.close()
print("File Created Successfully")
Output:
File Created Successfully
Important Points
x का अर्थ Exclusive Creation Mode है।
यह नई file create करता है।
Existing file को overwrite नहीं करता।
File पहले से मौजूद होने पर FileExistsError देता है।
यह अनजाने में existing data overwrite होने से बचाता है।