Importing Modules

import statement consists of the following:

  • The import keyword
  • The name of the module
  • Optionally, more module names, as long as they are separated by commas

Example:

import random
for i in range(5):
    print(random.randint(1, 10))

Note: don’t overwrite module names like os, sys, random, etc.

Alternative form:

from random import *

Importing multiple modules:

import random, sys, os, math