Which file opening mode creates a new file but raises an error if the file already exists?

Options

  • A. r
  • B. w
  • C. x
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

C. x

Detailed Explanation

The x mode opens a file for exclusive creation. It raises FileExistsError if the file already exists.