Bird
Raised Fist0

Which of the following is the correct syntax to write the string 'Data' to a file object named f?

easy📝 Syntax Q3 of Q15
Python - File Handling Fundamentals
Which of the following is the correct syntax to write the string 'Data' to a file object named f?
Awrite(f, 'Data')
Bf.write('Data')
Cf.write_data('Data')
Df.writeLine('Data')
Step-by-Step Solution
Solution:
  1. Step 1: Recall file write method syntax

    The correct method to write string data to a file object is f.write(string).
  2. Step 2: Check other options

    Other options are invalid method calls or functions not defined for file objects.
  3. Final Answer:

    f.write('Data') -> Option B
  4. Quick Check:

    Write string = f.write(string) [OK]
Quick Trick: Use f.write('text') to write strings [OK]
Common Mistakes:
MISTAKES
  • Using wrong method names
  • Trying to call write as a function
  • Confusing write with print

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes