Search Header Logo
Summer Lesson 25

Summer Lesson 25

Assessment

Presentation

Computers

9th - 12th Grade

Practice Problem

Hard

Created by

Robert Giordano

FREE Resource

6 Slides • 3 Questions

1

media

Lesson 25

Creating Modules

2

media

Consider a module to be the same as a code library.

A file containing a set of functions you want to include in your application.

Simply, a module is a file consisting of Python code. A module can define functions,
classes and variables. A module can also include runnable code.

The benefit of modules is that it provides a way to share reusable functions.

What is a Module?

3

media
media

To create a module just save the code you want in a file with the file extension .py:

Creating a Module

4

media
media

Use a Module

In your other file:

Import the module named mymodule, and call the greeting function:

Note: When using a function from a module, use the syntax: module_name.function_name.

5

Fill in the Blanks

media image

6

media
media
media

Variables in Module

Save this code in the file mymodule.py :

In your main file:

7

Fill in the Blanks

media image

8

media
media

Renaming a Module

You can name the module file whatever you like, but it must have the file
extension .py

You can create an alias when you import a module, by using the as keyword:

Create an alias for mymodule called mx:

9

Fill in the Blanks

media image
media

Lesson 25

Creating Modules

Show answer

Auto Play

Slide 1 / 9

SLIDE