PCEP-30-02 · Question #157
What is the expected behavior of the following program? ``python print("Hello!") ``
The correct answer is A. The program will output Hello! to the screen. Option A is correct because Python's print() function outputs its argument to standard output (the screen) without the surrounding quotation marks - the quotes in the source code are string delimiters, not part of the value itself. Why the distractors are wrong: B is wrong…
Question
print("Hello!")
Options
- AThe program will output Hello! to the screen
- BThe program will generate an error on the screen
- CThe program will output "Hello!" to the screen
- DThe program will output "Hello!" to the screen
How the community answered
(23 responses)- A78% (18)
- B4% (1)
- C4% (1)
- D13% (3)
Explanation
Option A is correct because Python's print() function outputs its argument to standard output (the screen) without the surrounding quotation marks - the quotes in the source code are string delimiters, not part of the value itself.
Why the distractors are wrong:
- B is wrong because
print("Hello!")is valid Python syntax with no errors - it will execute successfully every time. - C and D are wrong because they show
"Hello!"with quotation marks in the output. Python'sprint()strips the string delimiters; only the contents between the quotes are printed.
Memory tip: Think of quotation marks as a container, not the contents. print() opens the container and displays only what's inside - so "Hello!" on screen becomes Hello!, not "Hello!".
Community Discussion
No community discussion yet for this question.