TechBeamersTechBeamers
  • Learn ProgrammingLearn Programming
    • Python Programming
      • Python Basic
      • Python OOP
      • Python Pandas
      • Python PIP
      • Python Advanced
      • Python Selenium
    • Python Examples
    • Selenium Tutorials
      • Selenium with Java
      • Selenium with Python
    • Software Testing Tutorials
    • Java Programming
      • Java Basic
      • Java Flow Control
      • Java OOP
    • C Programming
    • Linux Commands
    • MySQL Commands
    • Agile in Software
    • AngularJS Guides
    • Android Tutorials
  • Interview PrepInterview Prep
    • SQL Interview Questions
    • Testing Interview Q&A
    • Python Interview Q&A
    • Selenium Interview Q&A
    • C Sharp Interview Q&A
    • PHP Interview Questions
    • Java Interview Questions
    • Web Development Q&A
  • Self AssessmentSelf Assessment
    • Python Test
    • Java Online Test
    • Selenium Quiz
    • Testing Quiz
    • HTML CSS Quiz
    • Shell Script Test
    • C/C++ Coding Test
Search
  • Python Multiline String
  • Python Multiline Comment
  • Python Iterate String
  • Python Dictionary
  • Python Lists
  • Python List Contains
  • Page Object Model
  • TestNG Annotations
  • Python Function Quiz
  • Python String Quiz
  • Python OOP Test
  • Java Spring Test
  • Java Collection Quiz
  • JavaScript Skill Test
  • Selenium Skill Test
  • Selenium Python Quiz
  • Shell Scripting Test
  • Latest Python Q&A
  • CSharp Coding Q&A
  • SQL Query Question
  • Top Selenium Q&A
  • Top QA Questions
  • Latest Testing Q&A
  • REST API Questions
  • Linux Interview Q&A
  • Shell Script Questions
© 2024 TechBeamers. All Rights Reserved.
Reading: Python File Handling Quiz Part-1
Font ResizerAa
TechBeamersTechBeamers
Font ResizerAa
  • Python
  • SQL
  • C
  • Java
  • Testing
  • Selenium
  • Agile Concepts Simplified
  • Linux
  • MySQL
  • Python Quizzes
  • Java Quiz
  • Testing Quiz
  • Shell Script Quiz
  • WebDev Interview
  • Python Basic
  • Python Examples
  • Python Advanced
  • Python OOP
  • Python Selenium
  • General Tech
Search
  • Programming Tutorials
    • Python Tutorial
    • Python Examples
    • Java Tutorial
    • C Tutorial
    • MySQL Tutorial
    • Selenium Tutorial
    • Testing Tutorial
  • Top Interview Q&A
    • SQL Interview
    • Web Dev Interview
  • Best Coding Quiz
    • Python Quizzes
    • Java Quiz
    • Testing Quiz
    • ShellScript Quiz
Follow US
© 2024 TechBeamers. All Rights Reserved.
Python QuizzesPython Tutorials

Python File Handling Quiz Part-1

Last updated: Nov 05, 2023 12:10 am
By Meenakshi Agarwal
Share
7 Min Read
Python File Handling Quiz Part-1 for Beginners
Python File Handling Quiz Part-1 for Beginners
SHARE

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.

Contents
Q-1.  Which of the following command is used to open a file “c:\temp.txt” in read mode only?Q-2.  Which of the following command is used to open a file “c:\temp.txt” in write mode only?Q-3.  Which of the following command is used to open a file “c:\temp.txt” in append-mode?Q-4.  Which of the following statements are true regarding the opening modes of a file?Q-5. Which of the following commands can be used to read the “n” number of characters from a file using the file object <file>?Q-6. Which of the following commands can be used to read the entire contents of a file as a string using the file object <tmpfile>?Q-7. Which of the following commands can be used to read the next line in a file using the file object <tmpfile>?Q-8. Which of the following commands can be used to read the remaining lines in a file using the file object <tmpfile>?Q-9. What does the <readlines()> method return?Q-10. Which of the following functions can be used to check if a file “logo” exists?Q-11. Which of the following functions displays a file dialog for opening an existing file?Q-12. Which of the following functions displays a file dialog for saving a file?Q-13. Which of the following command is used to open a file “c:\temp.txt” for writing in binary format only?Q-14. Which of the following command is used to open a file “c:\temp.txt” for reading in binary format only?Q-15. Which of the following functions do you use to write data in binary format?Quick Suggestions

Undoubtedly, 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.

Now, attempt the below Python file handling quiz part-1 and answer each question carefully.

Check out the Quiz on Python File Handling Basics!

Q-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”)
B. infile = open(“c:\\temp.txt”, “r”)
C. infile = open(file = “c:\temp.txt”, “r+”)
D. infile = open(file = “c:\\temp.txt”, “r+”)

Hover 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”)
B. outfile = open(“c:\\temp.txt”, “w”)
C. outfile = open(file = “c:\temp.txt”, “w+”)
D. outfile = open(file = “c:\\temp.txt”, “w+”)

Hover 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”)
B. outfile = open(“c:\\temp.txt”, “rw”)
C. outfile = open(“c:\temp.txt”, “w+”)
D. outfile = open(“c:\\temp.txt”, “r+”)
E. outfile = open(“c:\\temp.txt”, “a”)

Hover 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.
B. When you open a file for writing, if the file does not exist, an error occurs.
C. When you open a file for reading, if the file does not exist, the program will open an empty file.
D. When you open a file for writing, if the file does not exist, a new file is created.
E. When you open a file for writing, if the file exists, the existing file is overwritten with the new file.

Hover here to view the answer!
Answer. A, D, and E

 

Q-5. Which of the following commands can be used to read the “n” number of characters from a file using the file object <file>?

A. file.read(n)
B. n = file.read()
C. file.readline(n)
D. file.readlines()

Hover here to view the answer!
Answer. A

 

Q-6. Which of the following commands can be used to read the entire contents of a file as a string using the file object <tmpfile>?

A. tmpfile.read(n)
B. tmpfile.read()
C. tmpfile.readline()
D. tmpfile.readlines()

Hover here to view the answer!
Answer. B

 

Q-7. Which of the following commands can be used to read the next line in a file using the file object <tmpfile>?

A. tmpfile.read(n)
B. tmpfile.read()
C. tmpfile.readline()
D. tmpfile.readlines()

Hover here to view the answer!
Answer. C

 

Q-8. Which of the following commands can be used to read the remaining lines in a file using the file object <tmpfile>?

A. tmpfile.read(n)
B. tmpfile.read()
C. tmpfile.readline()
D. tmpfile.readlines()

Hover here to view the answer!
Answer. D

 

Q-9. What does the <readlines()> method return?

A. str
B. a list of lines
C. list of single characters
D. a list of integers

Hover here to view the answer!
Answer. B

 

Q-10. Which of the following functions can be used to check if a file “logo” exists?

A. os.path.isFile(logo)
B. os.path.exists(logo)
C. os.path.isfile(logo)
D. os.isFile(logo)

Hover here to view the answer!
Answer. C

 

Q-11. Which of the following functions displays a file dialog for opening an existing file?

A. tmpfile = askopenfilename()
B. tmpfile = asksaveasfilename()
C. tmpfile = openfilename()
D. tmpfile = saveasfilename()

Hover here to view the answer!
Answer. A

 

Q-12. Which of the following functions displays a file dialog for saving a file?

A. tmpfile = askopenfilename()
B. tmpfile = openfilename()
C. tmpfile = asksaveasfilename()
D. tmpfile = saveasfilename()

Hover here to view the answer!
Answer. C

 

Q-13. Which of the following command is used to open a file “c:\temp.txt” for writing in binary format only?

A. outfile = open(“c:\temp.txt”, “w”)
B. outfile = open(“c:\\temp.txt”, “wb”)
C. outfile = open(“c:\temp.txt”, “w+”)
D. outfile = open(“c:\\temp.txt”, “wb+”)

Hover here to view the answer!
Answer. B

 

Q-14. Which of the following command is used to open a file “c:\temp.txt” for reading in binary format only?

A. outfile = open(“c:\temp.txt”, “r”)
B. outfile = open(“c:\\temp.txt”, “rb”)
C. outfile = open(“c:\temp.txt”, “r+”)
D. outfile = open(“c:\\temp.txt”, “rb+”)

Hover here to view the answer!
Answer. B

 

Q-15. Which of the following functions do you use to write data in binary format?

A. write
B. output
C. dump
D. send

Hover here to view the answer!
Answer. C

 

Your Experience with this Python File Handling Quiz?

We hope that you enjoyed going through the above Python file handling quiz part-1. Though, you could have felt the questions were a bit basic but would have reminded you of the core file-handling principles in Python.

Quick Suggestions

  • Basics of Python File Handling
  • Read-Write File I/O in Python
  • File Handling in Python Quiz Part II
  • Beginners quiz on Python functions
  • Linux Basic Questions and Answers

TechBeamers will be providing new quizzes and tutorials in the near future. In the meantime, please keep reading and learning.

Thank you.

You Might Also Like

How to Connect to PostgreSQL in Python

Generate Random IP Address (IPv4/IPv6) in Python

Python Remove Elements from a List

How to Use Extent Report in Python

10 Python Tricky Coding Exercises

Meenakshi Agarwal Avatar
By Meenakshi Agarwal
Follow:
Hi, I'm Meenakshi Agarwal. I have a Bachelor's degree in Computer Science and a Master's degree in Computer Applications. After spending over a decade in large MNCs, I gained extensive experience in programming, coding, software development, testing, and automation. Now, I share my knowledge through tutorials, quizzes, and interview questions on Python, Java, Selenium, SQL, and C# on my blog, TechBeamers.com.
Previous Article 30 Quick Python Programming Questions On List, Tuple & Dictionary 30 Python Programming Questions On List, Tuple, and Dictionary
Next Article 7 Chrome Extensions to Find XPath 7 Best Chrome Extensions to Find XPath in Selenium

Popular Tutorials

SQL Interview Questions List
50 SQL Practice Questions for Good Results in Interview
SQL Interview Nov 01, 2016
Demo Websites You Need to Practice Selenium
7 Sites to Practice Selenium for Free in 2024
Selenium Tutorial Feb 08, 2016
SQL Exercises with Sample Table and Demo Data
SQL Exercises – Complex Queries
SQL Interview May 10, 2020
Java Coding Questions for Software Testers
15 Java Coding Questions for Testers
Selenium Tutorial Jun 17, 2016
30 Quick Python Programming Questions On List, Tuple & Dictionary
30 Python Programming Questions On List, Tuple, and Dictionary
Python Basic Python Tutorials Oct 07, 2016
//
Our tutorials are written by real people who’ve put in the time to research and test thoroughly. Whether you’re a beginner or a pro, our tutorials will guide you through everything you need to learn a programming language.

Top Coding Tips

  • PYTHON TIPS
  • PANDAS TIPSNew
  • DATA ANALYSIS TIPS
  • SELENIUM TIPS
  • C CODING TIPS
  • GDB DEBUG TIPS
  • SQL TIPS & TRICKS

Top Tutorials

  • PYTHON TUTORIAL FOR BEGINNERS
  • SELENIUM WEBDRIVER TUTORIAL
  • SELENIUM PYTHON TUTORIAL
  • SELENIUM DEMO WEBSITESHot
  • TESTNG TUTORIALS FOR BEGINNERS
  • PYTHON MULTITHREADING TUTORIAL
  • JAVA MULTITHREADING TUTORIAL

Sign Up for Our Newsletter

Subscribe to our newsletter to get our newest articles instantly!

Loading
TechBeamersTechBeamers
Follow US
© 2024 TechBeamers. All Rights Reserved.
  • About
  • Contact
  • Disclaimer
  • Privacy Policy
  • Terms of Use
TechBeamers Newsletter - Subscribe for Latest Updates
Join Us!

Subscribe to our newsletter and never miss the latest tech tutorials, quizzes, and tips.

Loading
Zero spam, Unsubscribe at any time.
x