Exploring File Operations in Python

Quiz
•
Computers
•
12th Grade
•
Easy
Harmeet Kaur
Used 1+ times
FREE Resource
20 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
20 sec • 1 pt
What function is used to read a text file in Python?
loadText()
fetchFile()
readFile()
open()
2.
MULTIPLE CHOICE QUESTION
20 sec • 1 pt
How do you write a string to a text file in Python?
with open('filename.txt', 'r') as file: file.write('Your string here')
file.write_string('Your string here')
with open('filename.txt', 'w') as file: file.write('Your string here')
open('filename.txt') as file: file.write('Your string here')
3.
MULTIPLE CHOICE QUESTION
20 sec • 1 pt
What mode should you use to open a file for reading in Python?
r
x
a
w
4.
MULTIPLE CHOICE QUESTION
20 sec • 1 pt
What is the purpose of the 'with' statement when handling files?
The 'with' statement is a way to format file names.
The 'with' statement is used to create a new file.
The 'with' statement ensures proper resource management by automatically closing the file after its block of code is executed.
The 'with' statement allows multiple files to be opened simultaneously.
5.
MULTIPLE CHOICE QUESTION
20 sec • 1 pt
How can you read all lines from a text file at once?
Use 'file.readlines(filename)'
Use 'open(filename) as file: lines = file.read()'
Use 'with open(filename) as file: content = file.getlines()'
Use 'with open(filename, 'r') as file: lines = file.readlines()' or 'content = file.read()'.
6.
MULTIPLE CHOICE QUESTION
20 sec • 1 pt
What method is used to write multiple lines to a text file?
save() method
append() method
writelines() method or write() in a loop
writeall() method
7.
MULTIPLE CHOICE QUESTION
20 sec • 1 pt
What is the difference between 'r' and 'w' modes in file handling?
The 'r' mode is for reading, while 'w' mode is for writing (and truncates existing files).
'r' mode creates a new file, while 'w' mode appends to existing files.
Both 'r' and 'w' modes are for reading files only.
'r' mode is for writing, 'w' mode is for reading.
Create a free account and access millions of resources
Similar Resources on Wayground
20 questions
iGCSE Computer Science: Programming Languages

Quiz
•
9th - 12th Grade
15 questions
File Handling in C++ Programming

Quiz
•
12th Grade
20 questions
12 CS One Mark 11-15

Quiz
•
12th Grade
15 questions
File Handling in Python - Grade 12 CBSE

Quiz
•
12th Grade
19 questions
Day 1 - Basics of Python

Quiz
•
12th Grade
18 questions
Graphics

Quiz
•
1st - 12th Grade
20 questions
Round-1 Technical Aptitude

Quiz
•
11th Grade - Professi...
19 questions
AP CSP Review

Quiz
•
11th - 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