What happens when open(‘data.txt’, ‘x’) is called and data.txt already exists?
Correct answer C. FileExistsError is raised
Explanation
Mode 'x' means exclusive creation: it creates a new file and fails with FileExistsError if the file is already there. This protects existing data from being overwritten by mistake, unlike 'w', which silently truncates an existing file to zero length.
Answer checked How we write and check questions
Discussion