Home  »  CodeSnippets   »   How to Write a File in Python

How to Write a File in Python

Posted: February 6, 2022 | by Site Host

f= open("filename.txt", "w")
f.write("hello")
f.close()

Open function is used to open the file. The first parameter is the file to open and the second parameter (w) makes the file writable.

Found this article interesting? Follow Brightwhiz on Facebook, Twitter, and YouTube to read and watch more content we post.

Share it!

See also  How to Check Laravel Version From Command-line