# Create a new text file and add some content with open('newfile.txt', 'w') as file: file.write("I am the file content!")
# Check if the file has been created print(os.listdir())
The open() function is used to open files in Python if they exist. If not, a new file with the given name will be created.
Learn Flask development and learn to build cool apps with our premium Python course on Udemy.