Home »
MCQs »
Python MCQs
Amongst which of the following function is / are used to create a file and writing data?
69. Amongst which of the following function is / are used to create a file and writing data?
- append()
- open()
- close()
- None of the mentioned above
Answer: B) open()
Explanation:
To create a text file, we call the open() method and pass it the filename and the mode parameters to the function. If a file with the same name already exists, the open() function will behave differently depending on whether the write or append mode is used to open the file. Write mode (w) will cause all of the existing contents of the file to be lost, and a new file with the same name will be created with the same contents as the existing file.