Create a new file

We can create new files in python using the open function

The following code will create a new file if it doesn't exist, or replace its contents if it does.

myfile = open('names.txt', 'w')
myfile.write("David\n")
myfile.close()