Python Read Write Files
Read/Write Files
A. Create a File:
Creating a file is primarily done using the create (x) mode.
Example:
Output:
B. Write onto a File:
This method writes content onto a file.
Example:
Output:
If the file already exists with some content of its own, then this mode overwrites it.
Example:
Output:
C. Read a File:
This method allows us to read the contents of the file.
Example:
Output:
D. Append a File:
This method appends content into a file.
Example:
Output:
However, If the file exists already with some content in it, then the new content gets appended.
Example:
Output: