File Handling in Python -Revision test

Quiz
•
Computers
•
12th Grade
•
Hard
Naresh K Rana
Used 2+ times
FREE Resource
30 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
45 sec • 1 pt
A text file story.txt contains 500 lines. Which method is MOST memory-efficient for counting the number of lines?
len(f.readlines())
f.read().count("\n")
Iterating with for line in f and counting
f.readline() repeatedly storing in a list
2.
MULTIPLE CHOICE QUESTION
45 sec • 1 pt
A text file contains: Hello Python 123 Code What will f.read().split() return?
['Hello', 'Python', '123', 'Code']
['Hello Python', '123 Code']
['Hello Python\n123 Code']
['Hello', 'Python\n123', 'Code']
3.
MULTIPLE CHOICE QUESTION
45 sec • 1 pt
Which statement is TRUE about file reading in Python?
read() reads line by line
readline() reads the whole file
readlines() reads entire file into a list
read() returns list of strings
4.
MULTIPLE CHOICE QUESTION
45 sec • 1 pt
If a text file pointer is at the end after reading, which function resets it to the beginning?
f.restart()
f.flush()
f.seek(0)
f.reset()
5.
MULTIPLE CHOICE QUESTION
45 sec • 1 pt
Consider: f=open("data.txt","r") print(f.readline(4)) If file contains "Python", output will be:
"Python"
"Pyth"
"Py"
Error
6.
MULTIPLE CHOICE QUESTION
45 sec • 1 pt
To count the number of words in a text file, the best approach is:
Count spaces
Use .split() on each line
Use .count(" ")
Count characters
7.
MULTIPLE CHOICE QUESTION
45 sec • 1 pt
A file is opened in "r+" mode. Which is TRUE?
Can read but not write
Can write but not read
Can read and write both
Only creates a new file
Create a free account and access millions of resources
Similar Resources on Wayground
30 questions
File Handling in Python

Quiz
•
12th Grade
25 questions
APCSP DAT-1.D Data Compression

Quiz
•
9th - 12th Grade
25 questions
A2 CS General Knowledge Quiz

Quiz
•
12th Grade
30 questions
AP CSP Unit 2 Term Quiz

Quiz
•
10th - 12th Grade
25 questions
Computer Science KS4 - Unit 2 Data

Quiz
•
9th - 12th Grade
25 questions
PENILAIAN HARIAN 2 KELAS IX TIK

Quiz
•
9th - 12th Grade
25 questions
Autodesk Inventor User Interface & Commands

Quiz
•
9th - 12th Grade
25 questions
Operating Systems

Quiz
•
9th - 12th Grade
Popular Resources on Wayground
10 questions
Lab Safety Procedures and Guidelines

Interactive video
•
6th - 10th Grade
10 questions
Nouns, nouns, nouns

Quiz
•
3rd Grade
10 questions
9/11 Experience and Reflections

Interactive video
•
10th - 12th Grade
25 questions
Multiplication Facts

Quiz
•
5th Grade
11 questions
All about me

Quiz
•
Professional Development
22 questions
Adding Integers

Quiz
•
6th Grade
15 questions
Subtracting Integers

Quiz
•
7th Grade
9 questions
Tips & Tricks

Lesson
•
6th - 8th Grade
Discover more resources for Computers
20 questions
Digital Citizenship

Quiz
•
8th - 12th Grade
35 questions
Computer Baseline Examination 2025-26

Quiz
•
9th - 12th Grade
13 questions
Problem Solving Process

Quiz
•
9th - 12th Grade
10 questions
Understanding Algorithms with Pseudocode and Flowcharts

Interactive video
•
9th - 12th Grade
19 questions
AP CSP Unit 1 Review (code.org)

Quiz
•
10th - 12th Grade