In real-world application development, the logic that we implement uses some data and those data may come from different sources like databases, files, or API. As a python developer, we should have good knowledge of handling these different sources. In this tutorial, we will see how we can handle files and perform some operations using python in-built functions.
Basically, a file is a location to store information in non-volatile memory (Hard Disk). And, it is characterized by its name and extension.
When we want to perform some operation(Read/Write/Update) in a file, we will open it first. Then we perform our task and finally, we will close it to save the changes and deallocate the resources tied with the file.
Similarly, in python, File operation takes place in the following order:
- Open a file
- Perform operation (Read/Write/Update)
- Close the file