Skip to main content
Library homepage
 

Text Color

Text Size

 

Margin Size

 

Font Type

Enable Dyslexic Font
Engineering LibreTexts

7.0: Introduction

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

Landscape photograph of mountains with colors ranging from orange to pink to purple
Figure 7.1 credit: modification of work "Lone Pine Sunset", by Romain Guy/Flickr, Public Domain

As programs get longer and more complex, organizing the code into modules is helpful. This chapter shows how to define, import, and find new modules. Python's standard library provides over 200 built-in modules. Hundreds of thousands of other modules are available online.

A module is a .py file containing function definitions and other statements. The module's name is the file's name without the .py extension at the end. Ex: The following code, written in a file named greetings.py, defines a module named greetings.

    """Functions that print standard greetings."""

    def hello():
      print("Hello!")
    
    def bye():
      print("Goodbye!")

Technically, every program in this book is a module. But not every module is designed to run like a program. Running greetings.py as a program would accomplish very little. Two functions would be defined, but the functions would never be called. These functions are intended to be called in other modules.


This page titled 7.0: Introduction 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.

Support Center

How can we help?