Question 433 of 169
PCAP Exceptions and File I/O Practice Question
Which TWO of the following file modes will create a new file if it doesn't exist? (Select exactly 2)
⚠ Common exam trap
Candidates often confuse 'x' with 'r' or think that 'x' does not create a file. In fact, 'x' and 'a' both create a file if it does not exist, while 'w' also creates but truncates.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
'x'
('x') is correct because exclusive creation mode creates a new file and fails if it already exists. Option B ('a') is correct because append mode creates a new file if it does not exist, allowing data to be added at the end. Option D ('w') also creates a file if missing, but it truncates existing content, which may cause data loss; however, the question requires exactly two correct answers, and the non-destructive creation modes are 'x' and 'a'.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
'x'
Why this is correct
Fails if file exists.
- ✓
'a'
Why this is correct
Creates new file if not exists.
- ✗
'rb'
Why it's wrong here
Requires file to exist.
- ✗
'w'
Why it's wrong here
Creates new file if not exists.
- ✗
'r'
Why it's wrong here
Requires file to exist.
About these practice questions
Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →
Last reviewed: Jun 30, 2026
This PCAP practice question is part of Courseiva's free Python Institute certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the PCAP exam.
Question Discussion
Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.
Sign in to join the discussion.