PCEP-30-02 · Question #138
What is the expected behavior of the following program? print(\"Goodbye!\")
The correct answer is A. The program will generate an error message on the screen. Option A is correct because the backslash characters before the quotation marks (\") make this invalid Python syntax - Python expects plain " or ' to delimit strings, and placing \" outside a string literal causes a SyntaxError at runtime. Option B and C are wrong because they…
Question
Options
- AThe program will generate an error message on the screen
- BThe program will output "Goodbye!"
- CThe program will output Goodbye!
- DThe program will output ("Goodbye!")
How the community answered
(22 responses)- A77% (17)
- B5% (1)
- C14% (3)
- D5% (1)
Explanation
Option A is correct because the backslash characters before the quotation marks (\") make this invalid Python syntax - Python expects plain " or ' to delimit strings, and placing \" outside a string literal causes a SyntaxError at runtime. Option B and C are wrong because they describe the output of valid Python (print("Goodbye!")), but the escaped quotes mean this code never executes successfully enough to produce any output. Option D is wrong because Python's print() function never includes the surrounding parentheses in its output - that's not how any version of Python works. Memory tip: Think of the backslash as a "string-only escape hatch" - \" is only meaningful inside a string (e.g., "She said \"hi\""), never as a way to wrap one.
Community Discussion
No community discussion yet for this question.