Bird
Raised Fist0

What does the open('file.txt', 'r') command do in Python?

easy🧠 Conceptual Q11 of Q15
Python - File Handling Fundamentals
What does the open('file.txt', 'r') command do in Python?
AIt creates a new file named 'file.txt'.
BIt deletes the file 'file.txt'.
CIt opens the file 'file.txt' for reading.
DIt writes data to 'file.txt'.
Step-by-Step Solution
Solution:
  1. Step 1: Understand the open() function

    The open() function is used to open a file in a specified mode.
  2. Step 2: Recognize mode 'r'

    Mode 'r' means open the file for reading only, no writing or creating.
  3. Final Answer:

    It opens the file 'file.txt' for reading. -> Option C
  4. Quick Check:

    open() with 'r' = open for reading [OK]
Quick Trick: Mode 'r' always means read file only [OK]
Common Mistakes:
MISTAKES
  • Confusing 'r' with write mode 'w'
  • Thinking it creates a new file
  • Assuming it deletes the file

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes