A

Admin • 831.35K Points
Coach

Q. What is the correct way to open a file for writing in Python?

  • (A) open('file.txt', 'r')
  • (B) open('file.txt', 'x')
  • (C) open('file.txt', 'a')
  • (D) open('file.txt', 'w')
  • Correct Answer - Option(D)
  • Views: 19
  • Filed under category Python
  • Hashtags:

Explanation by: Admin
The mode `'w'` opens a file for writing. It will overwrite the file if it exists.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.