Skip to content

2.8/9 Module Basics

Modules

  • A module is a file containing Python code that can be used by other modules or scripts.
  • Programmer first imports module at beginning of file
  • A module is made available for use via the import statement.
  • Once a module is imported, any object defined in that module can be accessed using dot notation.
    • Ex: A variable speed_of_light defined in universe.py is accessed via universe.speed_of_light.

Importing Modules and Scripts

  • Importing Modules and Scripts
    • if the value of name is main then the file was executed as a script.

Untitled.png

Math Module

  • Contains number of math stuff: trig, log, etc
  • Function: list of statements that can be executed simply by referring to the function's name.
  • The process of invoking a function is referred to as a function call.
  • The item passed to a function is referred to as an argument.

Untitled%201.png