0
0
Pythonprogramming~20 mins

Import statement behavior in Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Import Statement Behavior
📖 Scenario: You are organizing a small Python project with two files. One file contains a function, and the other file will use that function by importing it.
🎯 Goal: Learn how to use the import statement to access functions from another file.
📋 What You'll Learn
Create a Python file named helper.py with a function called greet that returns the string 'Hello from helper!'.
Create a Python file named main.py that imports the greet function from helper.py.
Call the greet function inside main.py and store the result in a variable called message.
Print the message variable in main.py.
💡 Why This Matters
🌍 Real World
In real projects, code is often split into multiple files to keep things organized. Importing lets you use code from other files easily.
💼 Career
Understanding imports is essential for working on larger Python projects and collaborating with others.
Progress0 / 4 steps
1
Create the helper function
Create a file named helper.py and write a function called greet that returns the string 'Hello from helper!'. Write exactly this function definition:
Python
Need a hint?

Remember to use def to define a function and return to send back the string.

2
Import the greet function
In a new file named main.py, write an import statement to import the greet function from the helper module.
Python
Need a hint?

Use the syntax from module_name import function_name.

3
Call the greet function
In main.py, call the greet function and store its return value in a variable called message.
Python
Need a hint?

Call the function by writing greet() and assign it to message.

4
Print the message
In main.py, print the variable message to display the greeting.
Python
Need a hint?

Use print(message) to show the greeting on the screen.