Check your understanding of the previous reading: modules, packages and the import statement.
True or false: import is a function that takes in the name of a module and loads the functions, variables, and other definitions.
Select one answer, then check.
import does load a module's functions, variables and other definitions, but it isn't a function: it's a keyword that starts an import statement. You write import math, without parentheses. Trying to call it like a function, as in import(math), is a SyntaxError.import is a keyword that starts a statement, not a function. A function is called with parentheses, like print("hi"); an import is written import math, and import(math) is a SyntaxError.Compare how the reading writes an import, import math, with how you call a function such as print(...). What is missing from the import?
Review the documentation for the built-in math module. Which of the following are functions available from it?
Select all answers that apply, then check.
math.sqrt computes a square root: math.sqrt(16) is 4.0.math.log computes a logarithm. With one argument it's the natural logarithm (base e); a second argument picks the base, so math.log(8, 2) is 3.0.math. Only two bases get a function of their own, log2 and log10. For base 4 you write math.log(x, 4).math.log10 computes the base-10 logarithm: math.log10(1000) is 3.0.math. The exponential function is called math.exp. To raise a number to a power, use the ** operator (or math.pow).math. You add numbers with the + operator; the math module has no add.Three of the six are real. Not every logarithm base gets its own function, the exponential function has a shorter name, and one of the options is something Python does with an operator instead.
Which of the following is the best description of this line of code?
from math import sqrt as square_root
Select one answer, then check.
from math import sqrt loads sqrt from the math module, and as square_root gives it a new name in your program. Afterwards you call it as square_root(16); the name sqrt itself is not defined.math is the module and sqrt the function. The word right after from is always the module.import, and the new name comes after as.math has no square_root function; square_root is the new name given to sqrt.Read the line from left to right: from names the module, import names what you take from it, and as gives that a new name.
A contains , which in turn can provide functions, , and more after being imported.
Look back at the reading:
The grammar helps too: the first blank comes right after A, so it takes a singular word.
Completed sentence:
A package contains modules, which in turn can provide functions, variables, and more after being imported.
Distractors (not used): for loops, if statements. Those are kinds of code you write, not definitions a module makes available when it is imported.