Editor settings

General settings

Save settings

Learn to program with Python

Importing a module #

Now that we have a module (the file named greetings.py), we can start importing the module use whatever is inside.

To import a module, we use the import statement followed by the name of the module:

import module_name

For example, to import the greetings module, we can use:

import greetings

Once we have imported a module, we can access variables, functions, classes, objects, etc., in that module by using the dot notation . followed by the name of the thing you need. Here's an example of using the greet() function inside the greetings module:

import greetings

greetings.greet("James") # Hello James!

Exercise #

Import the module greetings and call the greet() function with your name.

Tests #

  • Import the module greetings
  • Call the greet() function with your name
Output will be displayed here