How to Create a New File Using Open() Method in Python


In this example we will show how to create a new file using the open() method in Python.

Source Code

f = open("filename.txt", "x")

Output:

It will create a new empty file, returns an error if the file exist.
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments