write()
The file method that writes a string to a file, adding nothing extra, not even a newline.
In more detail
Write "\n" yourself at the end of each line. write accepts only strings in text mode, so convert numbers with str() or use an f-string. print(..., file=f) is an alternative that adds the newline.
Related terms
- file object — The object returned by open() that you read from or write to, and close when finished.
- newline — The invisible character that ends a line of text, written \n in most programming languages.
- open() — The built-in function that opens a file by name and returns a file object, for reading by default or for writing or appending.
Taught in
- Files: Writing And Reading — Hands-on Python: Complete Video Course & Book
- Chapter Two In One Sitting — Hands-on Python: Complete Video Course & Book
- Classes And Instances — Hands-on Python: Complete Video Course & Book