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