How to Create a New File in Python


In this example, we will learn how to create a new file if it does not exist in Python.

Source Code

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

Output:

It will create a file if the specified file does not exist.
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments