H13-311_V3.5 · Question #3
Which is wrong with the Python module time introduction method?
The correct answer is D. from time. Option D, from time, is syntactically incomplete and will raise a SyntaxError in Python. The from keyword must always be followed by a module name and then import with at least one name to import, such as from time import sleep. Options A, B, and C are all valid import forms…
Question
Which is wrong with the Python module time introduction method?
Options
- Aimport time
- Bfrom time import *
- Cimport time as t
- Dfrom time
How the community answered
(29 responses)- A3% (1)
- B17% (5)
- C7% (2)
- D72% (21)
Explanation
Option D, from time, is syntactically incomplete and will raise a SyntaxError in Python. The from keyword must always be followed by a module name and then import with at least one name to import, such as from time import sleep. Options A, B, and C are all valid import forms: import time loads the module under its own name, from time import * brings all public names into the current namespace, and import time as t loads the module with an alias. A useful way to remember this is that from never stands alone -- it always needs a partner import clause to complete the statement, just as "from the store" is an incomplete sentence without telling what you brought back.
Topics
Community Discussion
No community discussion yet for this question.