Library

External library can be imported using import command. There are several method to import external library


In [1]:
# Method 1

import math

# In this case library name shall be attached before function/variable name in the library
print(math.pi)


3.141592653589793

In [2]:
# Method 2

import math as mt

# it's possible to use nick-name for name space of library
print(mt.pi)


3.141592653589793

In [3]:
# Method 3

from math import pi, cos, sin

# only import specific function/variable
print(pi)
print(cos(pi/6), sin(pi/6))  # 30 deg


3.141592653589793
0.8660254037844387 0.49999999999999994

In [4]:
# Method 4

from math import *

# import every variable/function and merge name space
# !!! Not recommended !!!

print(pi)
print(cos(pi/4), sin(pi/4))


3.141592653589793
0.7071067811865476 0.7071067811865475

In [ ]: