Write Operation is the process of writing data to file by the program. This is done using the write() method available in the Python library.
The Python program is opened in 'w' mode, to write files.
Algorithm to Write to File in Python:
- Step 1: Open the file using 'w' mode. (if the file is not present the write mode will create a new one).
- Step 2: Get input from the user.
- Step 3: User the write() method to write the contents to the file.
- Step 4: Close the file.
Python program to write data to a file
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer