Python File Opening Mode
Multiple Choice Easy
Question
What does `open('file.txt', 'w')` do if the file exists?
Hint
'w' stands for write.
Explanation
Mode 'w' opens the file for writing. If the file exists, its contents are truncated (emptied). If it does not exist, a new file is created. Use 'a' to append without truncating, and 'r' to read.
Related Resources
Related Lessons
- File Handling
File modes.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.