Importing Library¶
There are two methods to import library functions:
- import <libName> # access function through: libName.functionName
- import <libName> as <shortLibName> # access function through: shortLibName.functionName
- from <libName> import * # all functions available at global namespace
- from <libName> import <functionName> # access function through: functionName
- from <libName> import <functions> as <shortFunctionName> # access function through shortFunctionName
Import Entire Library¶
Import As An Object¶
In [73]:
import math math.sqrt(9)
Out[73]:
3.0
Use as for aliasing library name. This is useful if you have conflicting library name
In [74]:
import math as m m.sqrt(9)
Out[74]:
3.0
Import Into Global Name Space¶
All functions in the library accessible through global namespace
from <libName> import *
Import Specific Function¶
In [75]:
from math import sqrt print (sqrt(9))
3.0
Use as for aliasing function name
In [76]:
from math import sqrt as sq print (sq(9))
3.0