Skip to main content
Library homepage
 

Text Color

Text Size

 

Margin Size

 

Font Type

Enable Dyslexic Font
Engineering LibreTexts

7.6: Chapter Summary

( \newcommand{\kernel}{\mathrm{null}\,}\)

Highlights from this chapter include:

  • Programs can be organized into multiple .py files (modules). The import keyword allows a program to use functions defined in another .py file.
  • The from keyword can be used to import specific functions from a module. However, programs should avoid importing (or defining) multiple functions with the same name.
  • Modules often include the line if __name__ == "__main__" to prevent code from running as a side effect when the module is imported by other programs.
  • When working in a shell, the help() function can be used to look up the documentation for a module. The documentation is generated from the docstrings.
  • Python comes with over 200 built-in modules and hundreds of thousands of third-party modules. Programmers can search for modules on docs.python.org and pypi.org.
Statement Description

import module

Imports a module for use in another program.

from module import function

Imports a specific function from a module.

if __name__ == "__main__":

A line of code found at the end of many modules. This statement indicates what code to run if the module is executed as a program (in other words, what code not to run if this module is imported by another program).

help(module_name)

Shows the documentation for the given module. The documentation includes the module's docstring, followed by a list of functions defined in the module, followed by a list of global variables assigned in the module, followed by the module's file name.

help(function_name)

Shows the docstring for the given function.

date(2023, 2, 14)

Creates a date object representing February 14, 2023.
Requires: from datetime import date.

Table 7.3 Chapter 7 reference.

This page titled 7.6: Chapter Summary is shared under a CC BY 4.0 license and was authored, remixed, and/or curated by OpenStax via source content that was edited to the style and standards of the LibreTexts platform.

  • Was this article helpful?

Support Center

How can we help?