The write method
The write method writes a file and returns an integer representing the number of bytes written. In the method parameter, we specify the string that we need to write to the file.
Syntax
file.write(what we write)
Example
Let's write the string 'text1' to the file file.txt, and then read its contents:
res = open('file1.txt', 'w') # open file for writing print(res.write('text1'))
res = open('file1.txt', 'r') # open file for reading print(res.read())
The result of the executed code:
5
text1