Skip to main content

Files Handling In Python — Part 2 MCQs with Explanations

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

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

Verified Practice Questions

Interactive test mode with detailed academic worked solutions

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

Which of the following is not a valid mode to open a file?

Question 2 of 38
★ FPSC ★ PPSC

How can you copy the contents of one file to another in Python?

Question 3 of 38
★ FPSC ★ PPSC

Which one of the following is not attributes of file?

Question 4 of 38
★ FPSC ★ PPSC

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

Question 5 of 38
★ FPSC ★ PPSC

What will be the output of the following Python code? str = raw_input("Enter your input: "); print "Received input is : ", str

Question 6 of 38
★ FPSC ★ PPSC

What will be the output of the following Python code? fo = open("foo.txt", "rw+") print "Name of the file: ", fo.name # Assuming file has following 5 lines # This is 1st line # This is 2nd line # This is 3rd line # This is 4th line # This is 5th line for index in range(5): line = fo.next() print "Line No %d - %s" % (index, line) # Close opened file fo.close()

Question 7 of 38
★ FPSC ★ PPSC

What will be the output of the following Python code? f = None for i in range (5): with open("data.txt", "w") as f: if i > 2: break print(f.closed)

Question 8 of 38
★ FPSC ★ PPSC

How do you rename a file?

Question 9 of 38
★ FPSC ★ PPSC

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

Question 10 of 38
★ FPSC ★ PPSC

What will be the output of the following Python code? str = input("Enter your input: "); print "Received input is : ", str

Question 11 of 38
★ FPSC ★ PPSC

What is unpickling?

Question 12 of 38
★ FPSC ★ PPSC

The readlines() method returns . . . . . . . .

Question 13 of 38
★ FPSC ★ PPSC

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

Question 14 of 38
★ FPSC ★ PPSC

To read the next line of the file from a file object infile, we use . . . . . . . .

Question 15 of 38
★ FPSC ★ PPSC

How can you rename a file in Python?

Question 16 of 38
★ FPSC ★ PPSC

What is the pickling?

Question 17 of 38
★ FPSC ★ PPSC

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

Question 18 of 38
★ FPSC ★ PPSC

How do you close a file object (fp)?

Question 19 of 38
★ FPSC ★ PPSC

What is the use of seek() method in files?

Question 20 of 38
★ FPSC ★ PPSC

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

Question 21 of 38
★ FPSC ★ PPSC

To read the remaining lines of the file from a file object infile, we use . . . . . . . .

Question 22 of 38
★ FPSC ★ PPSC

What is the purpose of the a mode when opening a file in Python?

Question 23 of 38
★ FPSC ★ PPSC

Which function is used to close a file in python?

Question 24 of 38
★ FPSC ★ PPSC

How do you get the current position within the file?

Question 25 of 38
★ FPSC ★ PPSC

How do you delete a file?

Question 26 of 38
★ FPSC ★ PPSC

How can you remove a file in Python?

Question 27 of 38
★ FPSC ★ PPSC

Which of the following is not a valid attribute of a file object (fp)?

Question 28 of 38
★ FPSC ★ PPSC

What is the use of truncate() method in file?

Question 29 of 38
★ FPSC ★ PPSC

How do you change the file position to an offset value from the start?

Question 30 of 38
★ FPSC ★ PPSC

How can you open a file for both reading and writing in Python?

Question 31 of 38
★ FPSC ★ PPSC

What is the difference between r+ and w+ modes?

Question 32 of 38
★ FPSC ★ PPSC

What is the purpose of the b mode when opening a file in Python?

Question 33 of 38
★ FPSC ★ PPSC

What is the output of the following code: with open('data.txt', 'r') as file: lines = file.read().splitlines() print(len(lines))

Question 34 of 38
★ FPSC ★ PPSC

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

Question 35 of 38
★ FPSC ★ PPSC

What will be the output of the following Python code? fo = open("foo.txt", "wb") print "Name of the file: ", fo.name fo.flush() fo.close()

Question 36 of 38
★ FPSC ★ PPSC

What is the correct syntax of open() function?

Question 37 of 38
★ FPSC ★ PPSC

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

Question 38 of 38
★ FPSC ★ PPSC

Is it possible to create a text 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 →