ubuntu2004
Modules
So far we have been using Python's inbuilt functions like print()
and len()
. Python also comes with lots of other software called modules. There are modules for many biological applications such as bioinformatics, molecular signalling, machine learning, plotting graphs, statistics and maths, to name but a few.
To be able to use a module we have to import it. For example, to import the math
module, which contains standard maths functions like sine, log, etc., we place the following code at the start of our program:
Now we can use all of the maths functions contained in this module.
Run the following code to calculate the square root of a number.
To get a list of all the mathematical functions type help(math)
. There's also a lot of information available online. Most likely you will never need most of these, but it's worth knowing they are there in case you do need one of them.
The math module also contains the value of so that you don't have to remember it.
Remember the code you wrote to calculate a mean and median of a list of numbers? There is a Python module called statistics
that can do that for you.
A full list of functions in the statistics module is here.
We will be making a lot of use of modules in Exploratory Data Analysis next week.