Which of the following statements are true regarding the opening modes of a file
This Python file handling quiz provides multiple-choice questions(MCQ) to familiarize with Python file operations. This quiz test your knowledge of file operations such as opening a file, reading a file, writing a file, closing it, renaming a file, deleting a file, and various file methods. Show
Read Python File Handling to solve this quiz.
1. Select the correct mode to open a file for appending as well as reading 2. Select the incorrect file access mode 3. Select the correct access mode to open a file only for exclusive creation 4. If the file is opened in write mode and already exists, it truncates the existing content and places the filehandle at the beginning of the file. True False 5. Select the correct method to write a list of lines to a file 6. Select all true statements when a file is opened using the The with statement simplifies exception handling The file is automatically closed after leaving the block, and all the resources that are tied up with the file are released. Welcome to the Python file handling quiz part-1. In this quiz, we’ve added 15 basic questions that cover topics related to file handling functions and access modes. Undoubtedly, the files are a key component of almost all applications. But it has been a challenge for programmers to use them in an optimized manner. Because the mishandling of files can pull down the performance of any application miserably. This topic is important for programmers but has the same relevance for automation testers. One could use it for file processing software like Accounting or Hospitality management whereas another may find it useful for reading configuration files or logging errors. If you are a software engineer or an automation tester just beginning to learn Python and file handling, then better walk through the following tutorial. It’ll give you a detailed overview of the Python file handling and demonstrate their usage with examples. ➡ Python File Handling Tutorial Now, attempt the below Python file handling quiz part-1 and answer each question carefully. Python File Handling Quiz Part-1 for BeginnersQ-1. Which of the following command is used to open a file “c:\temp.txt” in read-mode only?A. infile = open(“c:\temp.txt”, “r”) Click here to view the answer. Answer. B
Q-2. Which of the following command is used to open a file “c:\temp.txt” in write-mode only?A. outfile = open(“c:\temp.txt”, “w”) Click here to view the answer. Answer. B
Q-3. Which of the following command is used to open a file “c:\temp.txt” in append-mode?A. outfile = open(“c:/temp.txt”, “a”) Click here to view the answer. Answer. A and E
Q-4. Which of the following statements are true regarding the opening modes of a file?A. When you open a file for reading, if the file does not exist, an error occurs. Click here to view the answer. Answer. A, D and E
Q-5. Which of the following commands can be used to read “n” number of characters from a file using the file object |