ReferenceFile methods
file.write()
Writes a string to the file, adding no newline of its own.
Signature
f.write(text)Parameters
| Name | Means |
|---|---|
text | what to write |
Returns
The number of characters written.
Example
Python
with open("notes.txt", "w", encoding="utf-8") as f:
print(f.write("hello"))
f.write("\nsecond\n")
with open("notes.txt", encoding="utf-8") as f:
print(f.read().strip())Output
5 hello second