search

What is the use of the "open" function in Python?

The "open" function in Python is used to open a file for reading or writing. It takes two parameters: the name of the file and the mode in which to open the file (e.g., 'r' for reading, 'w' for writing, etc.). The open function returns a file object that can be used to perform various operations on the file, such as reading, writing, and closing the file. For example:

f = open("example.txt", "r")

This opens the file "example.txt" in read mode and returns a file object that can be used to access the contents of the file.

Related Questions You Might Be Interested