Modular Programming

Modular Programming is coding method that separates the program into independent, interchangeable parts

Structure of a Program

A Python program is constructed from code blocks

A block is a piece of Python program text that is executed as a unit

The following are blocks:

Names and Binding

Names refer to objects

Names are introduced by name binding operations

The following constructs bind names:

The import System

The import System

Python code in one module gains access to the code in another module by the process of importing it

The import statement is the most common way of invoking the import machinery

import math

The import statement (with no from clause) is executed in 2 steps:

  1. find a module, loading and initializing it if necessary
  2. define a name or names in the local namespace for the scope where the import statement occurs.

When the statement contains multiple clauses (separated by commas) the two steps are carried out separately for each clause:

import math, os