🎓 EASYTUTORGUIDE · Complete Python Course

Very beginner → professional Python · 60 chapters · 900 topics

EasyTutorGuide

Chapter 20: Modules and Packages

Complete Python lesson for very beginners. Technical words are explained in simple language, and every outline topic includes a practical example, expected output, steps, and practice.

Python CourseVery Beginner Friendly15 TopicsExamples + Output20 Q&A
Chapter 20 · 15 topics
100%

Chapter Overview

This Python tutorial chapter covers Modules and Packages through 15 connected topics. Work through the examples in order, check the expected output, and complete the practice after each topic.

  • 20.1 What Is a Module?
  • 20.2 import
  • 20.3 from ... import
  • 20.4 Aliases
  • 20.5 Standard Library
  • Plus 10 additional Python topics in this chapter.

20.1 What Is a Module?

What Is a Module? is part of Modules and Packages. In simple language, it means a Python file that can provide reusable code.

It is one building block of modules and packages and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.

Technical words in simple language: What Is a Module? (a Python file that can provide reusable code).

Python / Practical Example

import math
print(math.sqrt(81))

Expected Output

9.0

Step-by-Step Explanation

  1. import makes a module available.
  2. Use module.name to access its contents.
  3. The standard-library math module provides sqrt().
Practice: Re-type the example for “What Is a Module?”, change one safe input, predict the result before running it, and explain in one sentence why the result changed.

20.2 import

import is part of Modules and Packages. In simple language, it means a Python idea used while learning modules and packages.

It is one building block of modules and packages and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.

Technical words in simple language: import (a Python idea used while learning modules and packages).

Python / Practical Example

import math
print(math.sqrt(81))

Expected Output

9.0

Step-by-Step Explanation

  1. import makes a module available.
  2. Use module.name to access its contents.
  3. The standard-library math module provides sqrt().
Practice: Re-type the example for “import”, change one safe input, predict the result before running it, and explain in one sentence why the result changed.

20.3 from ... import

from ... import is part of Modules and Packages. In simple language, it means a Python idea used while learning modules and packages.

It is one building block of modules and packages and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.

Technical words in simple language: from ... import (a Python idea used while learning modules and packages).

Python / Practical Example

import math
print(math.sqrt(81))

Expected Output

9.0

Step-by-Step Explanation

  1. import makes a module available.
  2. Use module.name to access its contents.
  3. The standard-library math module provides sqrt().
Practice: Re-type the example for “from ... import”, change one safe input, predict the result before running it, and explain in one sentence why the result changed.

20.4 Aliases

Aliases is part of Modules and Packages. In simple language, it means a Python idea used while learning modules and packages.

It is one building block of modules and packages and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.

Technical words in simple language: Aliases (a Python idea used while learning modules and packages).

Python / Practical Example

import math
print(math.pi > 3)

Expected Output

True

Step-by-Step Explanation

  1. Read the example from top to bottom.
  2. Identify the value, object, or operation related to this topic.
  3. Change one small input and predict the result before running it.
Practice: Re-type the example for “Aliases”, change one safe input, predict the result before running it, and explain in one sentence why the result changed.

20.5 Standard Library

Standard Library is part of Modules and Packages. In simple language, it means a Python idea used while learning modules and packages.

It is one building block of modules and packages and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.

Technical words in simple language: Standard Library (a Python idea used while learning modules and packages).

Python / Practical Example

import math
print(math.pi > 3)

Expected Output

True

Step-by-Step Explanation

  1. Read the example from top to bottom.
  2. Identify the value, object, or operation related to this topic.
  3. Change one small input and predict the result before running it.
Practice: Re-type the example for “Standard Library”, change one safe input, predict the result before running it, and explain in one sentence why the result changed.

20.6 Creating Modules

Creating Modules is part of Modules and Packages. In simple language, it means a Python file that can provide reusable code.

It is one building block of modules and packages and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.

Technical words in simple language: Creating Modules (a Python file that can provide reusable code).

Python / Practical Example

import math
print(math.sqrt(81))

Expected Output

9.0

Step-by-Step Explanation

  1. import makes a module available.
  2. Use module.name to access its contents.
  3. The standard-library math module provides sqrt().
Practice: Re-type the example for “Creating Modules”, change one safe input, predict the result before running it, and explain in one sentence why the result changed.

20.7 __name__

__name__ is part of Modules and Packages. In simple language, it means a Python idea used while learning modules and packages.

It is one building block of modules and packages and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.

Technical words in simple language: __name__ (a Python idea used while learning modules and packages).

Python / Practical Example

def main():
    print("program started")

if __name__ == "__main__":
    main()

Expected Output

program started

Step-by-Step Explanation

  1. Python sets __name__ for each module.
  2. A directly executed file receives "__main__".
  3. The guard lets reusable imports avoid running the program entry point automatically.
Practice: Re-type the example for “__name__”, change one safe input, predict the result before running it, and explain in one sentence why the result changed.

20.8 __main__

__main__ is part of Modules and Packages. In simple language, it means a Python idea used while learning modules and packages.

It is one building block of modules and packages and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.

Technical words in simple language: __main__ (a Python idea used while learning modules and packages).

Python / Practical Example

def main():
    print("program started")

if __name__ == "__main__":
    main()

Expected Output

program started

Step-by-Step Explanation

  1. Python sets __name__ for each module.
  2. A directly executed file receives "__main__".
  3. The guard lets reusable imports avoid running the program entry point automatically.
Practice: Re-type the example for “__main__”, change one safe input, predict the result before running it, and explain in one sentence why the result changed.

20.9 Packages

Packages is part of Modules and Packages. In simple language, it means a way to organize or distribute related Python code.

It is one building block of modules and packages and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.

Technical words in simple language: Packages (a way to organize or distribute related Python code).

Python / Practical Example

import math
print(math.sqrt(81))

Expected Output

9.0

Step-by-Step Explanation

  1. import makes a module available.
  2. Use module.name to access its contents.
  3. The standard-library math module provides sqrt().
Practice: Re-type the example for “Packages”, change one safe input, predict the result before running it, and explain in one sentence why the result changed.

20.10 __init__.py

__init__.py is part of Modules and Packages. In simple language, it means a Python idea used while learning modules and packages.

It is one building block of modules and packages and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.

Technical words in simple language: __init__.py (a Python idea used while learning modules and packages).

Python / Practical Example

import math
print(math.pi > 3)

Expected Output

True

Step-by-Step Explanation

  1. Read the example from top to bottom.
  2. Identify the value, object, or operation related to this topic.
  3. Change one small input and predict the result before running it.
Practice: Re-type the example for “__init__.py”, change one safe input, predict the result before running it, and explain in one sentence why the result changed.

20.11 Absolute Imports

Absolute Imports is part of Modules and Packages. In simple language, it means a Python idea used while learning modules and packages.

It is one building block of modules and packages and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.

Technical words in simple language: Absolute Imports (a Python idea used while learning modules and packages).

Python / Practical Example

print(abs(-12))

Expected Output

12

Step-by-Step Explanation

  1. abs() returns distance from zero.
  2. A negative input becomes positive magnitude.
  3. The result is numeric.
Practice: Re-type the example for “Absolute Imports”, change one safe input, predict the result before running it, and explain in one sentence why the result changed.

20.12 Relative Imports

Relative Imports is part of Modules and Packages. In simple language, it means a Python idea used while learning modules and packages.

It is one building block of modules and packages and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.

Technical words in simple language: Relative Imports (a Python idea used while learning modules and packages).

Python / Practical Example

import math
print(math.sqrt(81))

Expected Output

9.0

Step-by-Step Explanation

  1. import makes a module available.
  2. Use module.name to access its contents.
  3. The standard-library math module provides sqrt().
Practice: Re-type the example for “Relative Imports”, change one safe input, predict the result before running it, and explain in one sentence why the result changed.

20.13 Module Search Path

Module Search Path is part of Modules and Packages. In simple language, it means a Python file that can provide reusable code.

It helps you prepare a reliable Python workspace so the same commands and files run in the environment you expect. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.

Technical words in simple language: Module Search Path (a Python file that can provide reusable code).

Python / Practical Example

import math
print(math.sqrt(81))

Expected Output

9.0

Step-by-Step Explanation

  1. import makes a module available.
  2. Use module.name to access its contents.
  3. The standard-library math module provides sqrt().
Practice: Re-type the example for “Module Search Path”, change one safe input, predict the result before running it, and explain in one sentence why the result changed.

20.14 Organizing Packages

Organizing Packages is part of Modules and Packages. In simple language, it means a way to organize or distribute related Python code.

It is one building block of modules and packages and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.

Technical words in simple language: Organizing Packages (a way to organize or distribute related Python code).

Python / Practical Example

import math
print(math.sqrt(81))

Expected Output

9.0

Step-by-Step Explanation

  1. import makes a module available.
  2. Use module.name to access its contents.
  3. The standard-library math module provides sqrt().
Practice: Re-type the example for “Organizing Packages”, change one safe input, predict the result before running it, and explain in one sentence why the result changed.

20.15 Reusable Code

Reusable Code is part of Modules and Packages. In simple language, it means a Python idea used while learning modules and packages.

It is one building block of modules and packages and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.

Technical words in simple language: Reusable Code (a Python idea used while learning modules and packages).

Python / Practical Example

import math
print(math.pi > 3)

Expected Output

True

Step-by-Step Explanation

  1. Read the example from top to bottom.
  2. Identify the value, object, or operation related to this topic.
  3. Change one small input and predict the result before running it.
Practice: Re-type the example for “Reusable Code”, change one safe input, predict the result before running it, and explain in one sentence why the result changed.

Common Beginner Mistakes

  • Copying code without predicting what each line does.
  • Ignoring the first useful error message or traceback location.
  • Mixing tabs/spaces or changing indentation accidentally.
  • Using data of the wrong type for an operation.
  • Trying to learn many advanced variations before mastering one small working example.

Chapter Practice

  1. Choose three topics from this chapter and re-type their examples without copying and pasting.
  2. For each example, change one input and predict the output first.
  3. Explain five technical terms from this chapter in your own beginner-friendly words.
  4. Create one small program that combines at least two chapter topics.
  5. Keep notes about errors you made and what fixed them.

Mini Project / Challenge

Create a small Python exercise that combines at least three ideas from Modules and Packages. Start with a tiny working version, test it, then improve it one step at a time.

  1. Choose three topics from this chapter.
  2. Write or adapt a small Python example using those topics.
  3. Predict the output before running the code.
  4. Test at least one different input.
  5. Write two sentences explaining what the program does and what you learned.

20 Questions & Answers

1. What is the main goal of Chapter 20?

The goal is to understand modules and packages through small explanations, examples, and practice.

2. Should I memorize every command or method?

No. Understand the pattern, practice the common form, and learn how to read documentation when you need exact details.

3. Why are the examples small?

Small examples isolate one idea at a time, which makes errors easier to understand and fix.

4. What should I do when an example gives an error?

Read the last part of the traceback, check spelling and indentation, confirm the required package or file exists, and compare the input types with what the operation expects.

5. Why should I predict output before running code?

Prediction forces you to reason about the program instead of only copying it.

6. What should I remember about What Is a Module??

Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.

7. What should I remember about import?

Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.

8. What should I remember about from ... import?

Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.

9. What should I remember about Aliases?

Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.

10. What should I remember about Standard Library?

Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.

11. What should I remember about Creating Modules?

Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.

12. What should I remember about __name__?

Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.

13. What should I remember about __main__?

Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.

14. What should I remember about Packages?

Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.

15. What should I remember about __init__.py?

Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.

16. What should I remember about Absolute Imports?

Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.

17. What should I remember about Relative Imports?

Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.

18. What should I remember about Module Search Path?

Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.

19. What should I remember about Organizing Packages?

Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.

20. What should I remember about Reusable Code?

Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.