Question:

Which of the following is not a valid mode to open a file?

Show Hint

When opening a file in Python, ensure you use valid modes like 'r', 'w', 'a', 'r+', 'w+', 'rb', 'wb', etc., and avoid invalid combinations like 'rw'.
Updated On: Apr 24, 2025
  • ab
  • rw
  • r+
  • w+
Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is B

Solution and Explanation

The valid file modes in Python are:
- 'r' for reading
- 'w' for writing
- 'a' for appending
- 'b' for binary mode
- '+' for reading and writing.
The mode 'rw' is invalid because it is a combination of read and write without specifying the file type (binary or text). The correct mode should be 'r+' or 'w+'.
Was this answer helpful?
0
0

Top Questions on File Handling in Python

View More Questions