tech beamers
  • Viral Tips 🔥
  • Free CoursesTop
  • TutorialsNew
    • Python Tutorial
    • Python Examples
    • C Programming
    • Java Programming
    • MySQL Tutorial
    • Selenium Tutorial
    • Selenium Python
    • Playwright Python
    • Software Testing
    • Agile Concepts
    • Linux Concepts
    • HowTo Guides
    • Android Topics
    • AngularJS Guides
    • Learn Automation
    • Technology Guides
    • Python
    • C
    • Java
    • MySQL
    • Linux
    • Web
    • Android
    • AngularJS
    • Playwright
    • Selenium
    • Agile
    • Testing
    • Automation
    • Best IDEs
    • How-To
    • Technology
    • Gaming
    • Branding
  • Interview & Quiz
    • SQL Interview
    • Testing Interview
    • Python Interview
    • Selenium Interview
    • C Sharp Interview
    • Java Interview
    • Web Development
    • PHP Interview
    • Python Quizzes
    • Java Quizzes
    • Selenium Quizzes
    • Testing Quizzes
    • HTML CSS Quiz
    • Shell Script Quizzes
    • Python Interview
    • SQL Query Interview
    • SQL Exercises
    • Selenium Interview
    • Playwright Interview
    • QA Interview
    • Manual Testing
    • Rest API Interview
    • Linux Interview
    • CSharp Interview
    • Python Function Quiz
    • Python String Quiz
    • Python OOP Quiz
    • Python DSA Quiz
    • ISTQB Quiz
    • Selenium Quiz
    • Java Spring Quiz
    • Java Collection Quiz
    • JavaScript Quiz
    • Shell Scripting Quiz
  • ToolsHot
    • Python Online Compiler
    • Python Code Checker
    • C Online Compiler
    • Review Best IDEs
    • Random Letter Gen
    • Random Num Gen
    • Online Python Compiler
    • Python Code Checker
    • Python Code Quality
    • Username Generator
    • Insta Password Generator
    • Google Password Generator
    • Free PDF Merger
    • QR Code Generator
    • Net Worth Calculator
tech beamers
Search
  • Viral Tips 🔥
  • Free CoursesTop
  • TutorialsNew
    • Python Tutorial
    • Python Examples
    • C Programming
    • Java Programming
    • MySQL Tutorial
    • Selenium Tutorial
    • Selenium Python
    • Playwright Python
    • Software Testing
    • Agile Concepts
    • Linux Concepts
    • HowTo Guides
    • Android Topics
    • AngularJS Guides
    • Learn Automation
    • Technology Guides
  • Interview & Quiz
    • SQL Interview
    • Testing Interview
    • Python Interview
    • Selenium Interview
    • C Sharp Interview
    • Java Interview
    • Web Development
    • PHP Interview
    • Python Quizzes
    • Java Quizzes
    • Selenium Quizzes
    • Testing Quizzes
    • HTML CSS Quiz
    • Shell Script Quizzes
  • ToolsHot
    • Python Online Compiler
    • Python Code Checker
    • C Online Compiler
    • Review Best IDEs
    • Random Letter Gen
    • Random Num Gen
Follow US
© TechBeamers. All Rights Reserved.
Python Quizzes

Python File Handling Quiz Part-1

Last updated: Mar 07, 2025 11:14 am
Meenakshi Agarwal
By Meenakshi Agarwal
No Comments
7 months ago
Share
6 Min Read
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.

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.

Check out the Quiz on Python File Handling Basics!

This topic is important for programmers but has the same relevance for automation testers. So, attempt the below Python file handling quiz part-1 and answer each question carefully.

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+”)

Show Answer

Option – 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+”)

Show Answer

Option – 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”)

Show Answer

Option – 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.

Show Answer

Option – 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()

Show Answer

Option – 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()

Show Answer

Option – 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()

Show Answer

Option – 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()

Show Answer

Option – 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

Show Answer

Option – 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)

Show Answer

Option – 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()

Show Answer

Option – 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()

Show Answer

Option – 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+”)

Show Answer

Option – 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+”)

Show Answer

Option – 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

Show Answer

Option – 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, learning, and subscribe to our YouTube channel.

Thank You.

Related

TAGGED:programmingpython file handling
Share This Article
Whatsapp Whatsapp LinkedIn Reddit Copy Link
Meenakshi Agarwal Avatar
ByMeenakshi Agarwal
Follow:
Meenakshi Agarwal, Founder of TechBeamers.com, holds a BSc from Lucknow University and MCA from Banasthali University. With 10+ years as a Tech Lead at Aricent Technologies, she delivers expert Python, Java, Selenium, SQL, and AI tutorials, quizzes, and interview questions.
Previous Article Python string functions and examples Python String Handling Quiz Part-2
Next Article Python file handling quiz part-2 for Experienced Programmers Python File Handling Quiz Part-2
Leave a Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

List of Topics

Stay Connected

FacebookLike
XFollow
YoutubeSubscribe
LinkedInFollow

Continue Reading

  • Python File Handling Quiz Part-2Oct 13
  • Python Functions Quiz Part-1Oct 16
  • Python Functions Quiz Part-2Oct 16
  • Python Quiz: Classes and Objects Part 1Oct 22
  • Python Quiz: Classes and Objects Part 2Oct 25
  • Python Quiz for Beginners Part-1Sep 24
  • Python Multithreading QuizNov 13
  • Python Programming Online Skill TestJan 13
  • Python Quiz for Beginners Part-2Feb 3
  • Python Entry-Level Quiz For DevelopersMar 2
View all →

RELATED TUTORIALS

Unix Shell Scripting Quiz for Beginners

Unix Shell Scripting Quiz for Beginners – 25 Questions

By Harsh S.
7 months ago
TOP PROGRAMMING BLOGS FOR BEGINNERS

🚀 Top Programming Blogs for Beginners in 2025

By Meenakshi Agarwal
2 months ago
Python programming quiz

Python Quiz for Beginners Part-1

By Meenakshi Agarwal
7 months ago
C++ Programming Quiz for Beginners

C++ Programming Quiz – Beginner Level

By Meenakshi Agarwal
7 months ago
© TechBeamers. All Rights Reserved.
  • About
  • Contact
  • Disclaimer
  • Privacy Policy
  • Terms of Use