7.1 Module basics
2.
a.
Many modules consist of function definitions only. The functions are intended to be called in other modules.
7.2 Importing names
3.
b.
A name error occurs when a variable name is not found, which might be due to a missing import statement.
4.
b.
This statement replaces the previously imported circle function,
even though
circle()
and area.circle()
have different parameters.
5.
a.
Assigning the area variable replaces the previously imported module with the integer
51
.
The variable can no longer be used to call functions in the area module.
6.
b.
The most recent definition of
hello()
requires one argument,
so this line would result in an error.
7.3 Top-level code
1.
b.
Whenever this module is imported, Python will output
"Defining sphere
function"
as a side effect.
2.
a.
Even though nothing is printed, calling the sphere function ten million
times causes a delay in the main program.
3.
a.
All code is at the top level, and no functions are defined.
Importing this module would run all code as a side effect.
4.
c.
The variable
__name__
is the module's name, unless the module was
run as the main program. In that case, __name__
is
"__main__"
.
7.4 The help function
1.
b.
The digits have 0 red and 0 green, so the color must be a shade of blue.
Navy is a darker version of standard blue,
#0000FF
.
3.
a.
The red, green, and blue values for orange are higher than the red, green, and blue values for green.
6.
a.
Function names that begin with an underscore are intended to be used only within the current module.
7.
b.
Only docstrings are included in the documentation. All comments are ignored by the help function.
9.
a.
Functions that begin with an underscore are intended to be used only within a module, not in other modules.
7.5 Finding modules
1.
a.
This reference describes the standard library, including built-in functions, types, and modules.
3.
a.
The
tkinter
module stands for Tk interface. Tk is a standard toolkit for creating windows, text boxes, buttons, and other graphical widgets.
5.
a.
According to the "Features" section of the documentation,
Arrow
's is a "fully-implemented, drop-in replacement for datetime
."
6.
a.
This function converts a color code to a color name. Ex:
hex_to_name("#daa520")
returns
"goldenrod"
.