Certified Associate in Python Programming (PCAP-31-03) — Question 110
Which of the following statements are true? (Choose two.)
Answer options
- A. if open()'s second argument is 'r', the file must exist or open will fail
- B. the second open() argument describes the open mode and defaults to 'w'
- C. if open()'s second argument is 'w' and the invocation succeeds, the previous file's content is lost
- D. closing an opened file is performed by the closefile() function
Correct answer: A, C
Explanation
Statement A is correct because when opening a file in read mode ('r'), the file must exist; otherwise, an error occurs. Statement C is also true because using 'w' mode will truncate the file and erase its previous contents if the file already exists. The other statements are incorrect as the default mode for open() is 'r', not 'w', and there is no closefile() function; the correct function to close a file is close().