import math

"""
Explanation: Modules
Most of the functionality in Python is provided by modules. The Python Standard Library is a large collection of modules that provides cross-platform implementations of common facilities such as access to the operating system, file I/O, string management, network communication, and much more.
References

The Python Language Reference: http://docs.python.org/3/reference/index.html
The Python Standard Library: http://docs.python.org/3/library/

To use a module in a Python program it first has to be imported. A module can be imported using the import statement.
For example, to import the module math, which contains many standard mathematical functions, we can do:
End of explanation
"""


import math

x = math.cos(2 * math.pi)

print(x)

"""
Explanation: This includes the whole module and makes it available for use later in the program. 
For example, we can do:
End of explanation
"""


from math import cos, pi

x = cos(2 * pi)

print(x)

"""
Explanation: Alternatively, we can chose to import all symbols (functions and variables) in a module to the current namespace (so that we don't need to use the prefix "math." every time we use something from the math module:
End of explanation
"""


from math import cos as cosine  # Now the `cos` function can be referenced as `cosine`

cosine(pi/2)

"""
Explanation: This is called selective Import
This pattern can be very convenient, but in large programs that include many modules it is often a good idea to keep the symbols from each module in their own namespaces, by using the import math pattern. This would elminate potentially confusing problems with name space collisions.
Btw, in case of namespace collisions (or to avoid namespace pollution) we may use the as keyword
End of explanation
"""


from math import *

print("Cosine Function: ", cos(pi))
print("Sin Function: ", sin(pi))
print("Logarithm: ", log(e))
print("Power function: ", pow(3, 3))

"""
Explanation: Finally, if we want to import everything from a module, we may the * character:
End of explanation
"""


import math

print(dir(math))

"""
Explanation: Looking at what a module contains, and its documentation
Once a module is imported, we can list the symbols it provides using the dir function:
End of explanation
"""


help(math.log)

"""
Explanation: And using the function help we can get a description of each function (almost .. not all functions have docstrings, as they are technically called, but the vast majority of functions are documented this way).
End of explanation
"""


