QuestionQ100

Miscellaneous (List Comprehensions, Lambdas, Closures, I/O)

Which of these statements are true?

Choose two
  • 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
Explanation

Read mode ('r') opens an existing file and fails if the file does not exist. Write mode ('w') truncates an existing file when the open operation succeeds, so its prior contents are lost. The default mode is 'r', and an open file is closed with its close() method.

Community Discussion

No comments yet. Be the first to start the discussion!