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')
πŸ’¬ Discuss
βœ… Correct Answer: (D) open('file.txt', 'w')
Explanation: The mode `'w'` opens a file for writing. It will overwrite the file if it exists.
Explanation by: Mr. Dubey
The mode `'w'` opens a file for writing. It will overwrite the file if it exists.

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
255
Total Visits
πŸ“½οΈ
1 y ago
Published
πŸŽ–οΈ
Mr. Dubey
Publisher
πŸ“ˆ
97%
Success Rate