
Python File Handling Quiz

Quiz
•
Computers
•
10th Grade
•
Medium

M Ellis
Used 4+ times
FREE Resource
25 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is the key function for working with files in Python?
file()
open()
read()
write()
Answer explanation
The key function for working with files in Python is open(), which is used to open a file and return a file object for reading, writing, or both.
2.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What does the 'r' mode do when opening a file in Python?
Reads and writes to the file
Appends to the file
Reads the file, error if the file does not exist
Creates the file
Answer explanation
The 'r' mode in Python opens a file for reading. It will throw an error if the file does not exist.
3.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Which mode should be used to open a file for appending in Python?
'r'
'w'
'a'
'x'
Answer explanation
The correct mode to open a file for appending in Python is 'a', which allows writing to the end of the file without truncating it.
4.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What happens if you try to open a file in 'x' mode and the file already exists?
The file is overwritten
The file is read normally
An error is returned
The file is appended to
Answer explanation
Opening a file in 'x' mode will return an error if the file already exists, preventing accidental overwriting of existing files.
5.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is the default mode when opening a file in Python?
Binary mode
Write mode
Append mode
Text mode
Answer explanation
The default mode when opening a file in Python is Text mode, which is used for reading and writing text files. It is denoted by 'r' or no mode specified.
6.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Which mode is represented by 'b' when handling files in Python?
Text mode
Binary mode
Append mode
Create mode
Answer explanation
The 'b' mode in Python represents Binary mode, which is used for handling files containing binary data like images or executable files.
7.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is the correct syntax to open a file named "demofile.txt" for reading in Python?
f = open_file("demofile.txt")
f = open("demofile.txt", "r")
f = read("demofile.txt")
f = file("demofile.txt")
Answer explanation
The correct syntax to open a file named 'demofile.txt' for reading in Python is f = open('demofile.txt', 'r').
Create a free account and access millions of resources
Similar Resources on Wayground
20 questions
Pengenalan Informatika

Quiz
•
10th Grade
21 questions
Python бағдарламау тілінен тест сұрақтары

Quiz
•
9th - 12th Grade
20 questions
Процедура және функция

Quiz
•
10th Grade
20 questions
Programming Fundamentals Part 2

Quiz
•
9th - 11th Grade
20 questions
File system in Windows 7

Quiz
•
9th Grade - University
30 questions
Python Basics (Easy)

Quiz
•
9th - 12th Grade
20 questions
Python Intermediate Quiz (Including pygame)

Quiz
•
3rd - 12th Grade
25 questions
File Extension Quiz

Quiz
•
9th - 12th Grade
Popular Resources on Wayground
10 questions
Video Games

Quiz
•
6th - 12th Grade
20 questions
Brand Labels

Quiz
•
5th - 12th Grade
15 questions
Core 4 of Customer Service - Student Edition

Quiz
•
6th - 8th Grade
15 questions
What is Bullying?- Bullying Lesson Series 6-12

Lesson
•
11th Grade
25 questions
Multiplication Facts

Quiz
•
5th Grade
15 questions
Subtracting Integers

Quiz
•
7th Grade
22 questions
Adding Integers

Quiz
•
6th Grade
10 questions
Exploring Digital Citizenship Essentials

Interactive video
•
6th - 10th Grade
Discover more resources for Computers
10 questions
Exploring Digital Citizenship Essentials

Interactive video
•
6th - 10th Grade
10 questions
Proper Keyboarding Techniques

Interactive video
•
6th - 10th Grade
10 questions
Understanding Computers: Hardware, Software, and Operating Systems

Interactive video
•
7th - 12th Grade
29 questions
AP CSP Unit 2 Review (Code.org)

Quiz
•
10th - 12th Grade