Skip to main content

Files Handling In Python — Part 1 MCQs with Explanations

Practice high-yield Programming & Software Development MCQs on Files Handling In Python — Part 1 with worked academic solutions for FPSC, PPSC, NTS, NITB, PTS.

Questions
40
Difficulty Level
Exam-Level
Target Exams
FPSC, PPSC, NTS...
Estimated Time
48 mins
Exam-Level FPSC PPSC NTS NITB PTS
Verified for Commission Syllabus • Oct 14, 2026
40

Verified Practice Questions

Interactive test mode with detailed academic worked solutions

Live Progress | 0/40 answered
✓ 0 correct ✗ 0 wrong 0% score
Question 1 of 40
★ FPSC ★ PPSC

How do you open a file named data.txt in read mode in Python?

Question 2 of 40
★ FPSC ★ PPSC

What is the purpose of the with statement in file handling?

Question 3 of 40
★ FPSC ★ PPSC

How can you write data to a file in Python?

Question 4 of 40
★ FPSC ★ PPSC

What does the read() method of a file object do?

Question 5 of 40
★ FPSC ★ PPSC

How can you read a single line from a file in Python?

Question 6 of 40
★ FPSC ★ PPSC

What is the purpose of the seek() method in file handling?

Question 7 of 40
★ FPSC ★ PPSC

How can you read the entire contents of a file line by line in Python?

Question 8 of 40
★ FPSC ★ PPSC

What is the output of the following code: with open('data.txt', 'a') as file: file.write('Appended line.') with open('data.txt', 'r') as file: content = file.read() print(content)

Question 9 of 40
★ FPSC ★ PPSC

How can you create a new file in Python if it doesn't exist?

Question 10 of 40
★ FPSC ★ PPSC

To open a file c:\scores.txt for reading, we use . . . . . . . .

Question 11 of 40
★ FPSC ★ PPSC

To open a file c:\scores.txt for appending data, we use . . . . . . . .

Question 12 of 40
★ FPSC ★ PPSC

How can you close a file in Python?

Question 13 of 40
★ FPSC ★ PPSC

What is the purpose of the tell() method in file handling?

Question 14 of 40
★ FPSC ★ PPSC

To open a file c:\scores.txt for writing, we use . . . . . . . .

Question 15 of 40
★ FPSC ★ PPSC

What is the purpose of the write() method in file handling?

Question 16 of 40
★ FPSC ★ PPSC

To read two characters from a file object infile, we use . . . . . . . .

Question 17 of 40
★ FPSC ★ PPSC

What is the output of the following code: file = open('data.txt', 'r') content = file.read() print(content)

Question 18 of 40
★ FPSC ★ PPSC

What is the output of the following code: with open('data.txt', 'w') as file: file.write('Hello, world!')

Question 19 of 40
★ FPSC ★ PPSC

What will be the output of the following code: with open('data.txt', 'r') as file: lines = file.readlines() print(len(lines))

Question 20 of 40
★ FPSC ★ PPSC

Correct syntax of file.writelines() is?

Question 21 of 40
★ FPSC ★ PPSC

Which is/are the basic I/O connections in file?

Question 22 of 40
★ FPSC ★ PPSC

What is the use of "a" in file handling?

Question 23 of 40
★ FPSC ★ PPSC

Which are the two built-in functions to read a line of text from standard input, which by default comes from the keyboard?

Question 24 of 40
★ FPSC ★ PPSC

How can you check the current position in a file in Python?

Question 25 of 40
★ FPSC ★ PPSC

How can you check if a file exists in Python before opening it?

Question 26 of 40
★ FPSC ★ PPSC

Which function is used to read single line from file?

Question 27 of 40
★ FPSC ★ PPSC

Which of the following are the modes of both writing and reading in binary format in file?

Question 28 of 40
★ FPSC ★ PPSC

To read the entire remaining contents of the file as a string from a file object infile, we use . . . . . . . .

Question 29 of 40
★ FPSC ★ PPSC

Which function is used to read all the characters?

Question 30 of 40
★ FPSC ★ PPSC

What is the current syntax of remove() a file?

Question 31 of 40
★ FPSC ★ PPSC

Which function is used to write all the characters?

Question 32 of 40
★ FPSC ★ PPSC

What will be the output of the following Python code? (If entered name is examveda) import sys print 'Enter your name: ', name = '' while True: c = sys.stdin.read(1) if c == '\n': break name = name + c print 'Your name is:', name

Question 33 of 40
★ FPSC ★ PPSC

What happens if no arguments are passed to the seek function?

Question 34 of 40
★ FPSC ★ PPSC

Correct syntax of file.readlines() is?

Question 35 of 40
★ FPSC ★ PPSC

Which of the following mode will refer to binary data?

Question 36 of 40
★ FPSC ★ PPSC

How do you get the name of a file from a file object (fp)?

Question 37 of 40
★ FPSC ★ PPSC

In file handling, what does this terms means "r, a"?

Question 38 of 40
★ FPSC ★ PPSC

What is the use of tell() method in python?

Question 39 of 40
★ FPSC ★ PPSC

Which function is used to write a list of string in a file?

Question 40 of 40
★ FPSC ★ PPSC

What does the w mode indicate when opening a file in Python?

✓ Link copied to clipboard
Continue Your Practice

Advance Html — Part 1

Master the next curriculum module with 40 exam-standard MCQs.

Next Practice Set →

💡 Examiner's Advisory for Programming & Software Development

In competitive commission exams (FPSC, PPSC, KPPSC, SPSC, CSS, PMS), questions are frequently phrased with distractor options designed to catch rote learners. Whenever you answer an MCQ, read the Detailed Academic Explanation and Conceptual Anchor to understand why the remaining options are incorrect.

More Modules in Programming & Software Development

View All →
📚

Study Guides

Topic summaries and syllabus breakdown

Explore Guides →
🎯

Complete Library

Search through 78,000+ verified MCQs

Browse Library →
📱

Mobile App

Offline mock tests and instant bookmarks

Get Mobile App →