kota's memex
import math
print(math.sqrt(16))  # => 4.0

Python modules are just ordinary Python files. You can write your own, and import them. The name of the module is the same as the name of the file.

If you have a Python script named math.py in the same folder as your current script, the file math.py will be loaded instead of the built-in Python module.

This happens because the local folder has priority over Python's built-in libraries.

specific function import

from math import ceil, floor
print(ceil(3.7))   # => 4
print(floor(3.7))  # => 3

star import

Not a good idea. This will import everything from the module into the top level scope so that the normal math. prefix is not needed.

from math import *

rename modules on import

import math as m
math.sqrt(16) == m.sqrt(16)  # => True

show imported functions and attributes

import math
dir(math)