H13-311_V3.5 · Question #250
" print" in Python 3 must be used with "()"
The correct answer is A. True. In Python 3, print was changed from a statement (Python 2) to a built-in function, so calling it always requires parentheses: print("hello"). Without the parentheses, you're just referencing the function object itself rather than calling it - Python won't print anything and…
Question
" print" in Python 3 must be used with "()"
Options
- ATrue
- BFalse
How the community answered
(37 responses)- A70% (26)
- B30% (11)
Explanation
In Python 3, print was changed from a statement (Python 2) to a built-in function, so calling it always requires parentheses: print("hello"). Without the parentheses, you're just referencing the function object itself rather than calling it - Python won't print anything and won't raise an error, which makes the bug easy to miss. Option B is wrong because Python 3 made this a hard requirement; the parenthesis-free print "hello" syntax is a syntax error in Python 3 (it only worked in Python 2). Memory tip: Think of print() like any other function call - just as you'd never write len "abc" without parentheses, print in Python 3 demands them too.
Topics
Community Discussion
No community discussion yet for this question.