Python Data File Handling

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By MariamaThomas201
M
MariamaThomas201
Community Contributor
Quizzes Created: 1 | Total Attempts: 191
| Attempts: 191
SettingsSettings
Please wait...
  • 1/12 Questions

    Which file content is human readable format ?

    • Binary File
    • Text File
Please wait...
About This Quiz

This quiz on Python Data File Handling assesses knowledge on file types, modes, operations, and handling techniques in Python. It covers text and binary file handling, file modes, and essential Python modules, enhancing practical file manipulation skills.

Python Data File Handling - Quiz

Quiz Preview

  • 2. 

    The  readlines() method return -----------------

    • List of integers

    • List of Lines

    • Single line

    Correct Answer
    A. List of Lines
    Explanation
    The readlines() method in Python returns a list of lines from a file. Each line is represented as a string element in the list. Therefore, the correct answer is "List of Lines".

    Rate this question:

  • 3. 

    In which mode  all the files are opened in by default.

    • Read mode

    • Append mode

    • Write mode

    Correct Answer
    A. Read mode
    Explanation
    By default, when files are opened, they are opened in read mode. This means that the file can only be read and its contents can be accessed, but no modifications can be made to the file. In read mode, the file pointer is positioned at the beginning of the file, allowing the user to read the file from the start.

    Rate this question:

  • 4. 

    Opening a file in append mode erases the previous data

    • True

    • False

    Correct Answer
    A. False
    Explanation
    Opening a file in append mode does not erase the previous data. Instead, it allows new data to be added to the end of the file without overwriting or deleting the existing content. This is useful when we want to add new information to a file without losing the existing data.

    Rate this question:

  • 5. 

    Given the following code …. File=open(“Mydata”,”a”) File.close()                              What type of file is mydata?

    • Binary File

    • Text File

    Correct Answer
    A. Text File
    Explanation
    The file "Mydata" is a text file because it is opened with the mode "a" which stands for append. This mode is typically used for writing text to a file.

    Rate this question:

  • 6. 

    From the following which file  mode is used to read from a binary file.

    • R

    • R+

    • Rb

    Correct Answer
    A. Rb
    Explanation
    The correct answer is "rb". In file modes, "r" is used to read from a file, but when dealing with binary files, the "b" is added to specify that the file is in binary format. This mode allows for reading binary data from the file.

    Rate this question:

  • 7. 

    When you open a  file  in a+ mode file pointer will be at

    • Beginning of File

    • End of File

    Correct Answer
    A. End of File
    Explanation
    When you open a file in a+ mode, the file pointer will be at the end of the file. This means that any data written to the file will be appended to the existing content. If there is no existing content in the file, the file pointer will still be at the end of the file, ready for data to be written.

    Rate this question:

  • 8. 

    Name the method used to know the current position of the file pointer

    • Seek()

    • Tell()

    Correct Answer
    A. Tell()
    Explanation
    The method used to know the current position of the file pointer is "tell()". This method returns the current position of the file pointer, which indicates the next byte that will be read or written. By using this method, we can keep track of the current position within a file and perform operations accordingly.

    Rate this question:

  • 9. 

    Name the module should be imported to  operate with binary file .

    • Sys

    • Os

    • Pickle

    Correct Answer
    A. Pickle
    Explanation
    The correct answer is pickle. The pickle module in Python provides functions for serializing and deserializing objects. It is used to convert complex objects into a byte stream, which can be stored or transmitted, and then convert it back into the original object. This module is commonly used for working with binary files, as it allows for easy storage and retrieval of data in a compact format.

    Rate this question:

  • 10. 

    Read the following code : F1=open(“main.txt”,”w”) F1.write(“BYE”) print(F1.tell()) if the file contains  “GOOD”  before execution . What will be display after the execution of the above code:

    • 7

    • 8

    • 9

    • 6

    Correct Answer
    A. 7
    Explanation
    The code opens a file named "main.txt" in write mode and assigns it to the variable F1. It then writes the string "BYE" to the file. The print(F1.tell()) statement returns the current position of the file pointer, which is the number of characters written to the file so far. Since "BYE" has 3 characters, the file pointer is at position 3. Therefore, the answer is 7.

    Rate this question:

  • 11. 

    Which module is required to use built in function dump()?

    • Math

    • Flush

    • Pickle

    Correct Answer
    A. Pickle
    Explanation
    The module required to use the built-in function dump() is pickle. The dump() function is used to serialize and save Python objects into a file. The pickle module provides the necessary functionality to perform this serialization process.

    Rate this question:

  • 12. 

    Current working directory / folder  can be determined by using ------------------ method .

    • Getdir()

    • Getcwd()  

    • Dirget()

    Correct Answer
    A. Getcwd()  
    Explanation
    The correct answer is "getcwd()". This method is used to determine the current working directory or folder.

    Rate this question:

Quiz Review Timeline (Updated): Mar 19, 2023 +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 19, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • May 12, 2020
    Quiz Created by
    MariamaThomas201
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.