Importing and using modules/libraries

--Originally published at Python

Importing helps you use libraries or modules already available in Python 3. This means you don’t have to create functions from scratch, instead you can use the ones that already exist to save time and effort. There are a lot of libraries you can import, each has specific functions, in this blog, I will only focus in the import Math.

Code:

import math

print(math.fabs(-8))
print(math.ceil(1.1))
print(math.factorial(4))

2import

As you can see, the first thing you need to do is import the module/library, then you have to call it with a variable. For example, I used “math.fabs” which returns the absolute value of a number. So as a variable I used -8 and the program returned 8. There are 2 more examples below, but there are way more libraries you could use. If you want to learn more about them, check this link. It has all the functions you can use, as well as other modules/libraries.