Python: File I/O
File input and output is one of the most practical skills in Python — reading configuration files, writing logs, processing CSVs, and more. This quiz covers the essentials of Python's file handling, from opening modes to context managers.
Questions test knowledge of open() modes (r, w, a, rb, wb), the with statement for safe file handling, reading methods (read, readline, readlines), writing, and working with file paths using the os and pathlib modules.
Clean file handling is also about avoiding common mistakes — unclosed files, wrong encoding, incorrect paths. This quiz covers the patterns that prevent those bugs.
Start quiz →
Opens in a new tab on Cletica
Sample questions3 of 10 shown
Q1
What file mode opens a file for writing and creates it if it doesn't exist, overwriting if it does?
Q2
Why is the 'with open()' statement preferred over just 'open()'?
Q3
What does file.readlines() return?
What This Quiz Covers
- open() function: modes r, w, a, x, rb, wb, r+
- Context managers: with open() as f — why and how
- Reading methods: read(), readline(), readlines(), iteration
- Writing: write(), writelines(), and newline handling
- File encoding: utf-8, errors parameter
- os.path vs pathlib.Path for file path operations
- Working with CSV files using the csv module
Cletica
Want to create your own quiz?
Build surveys and quizzes, share with anyone, collect responses — free to start.
Try Cletica for free →