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.


ARE YOU A LIBRARY MOUSE?

--Originally published at Coding The Future

Image by Dmitrij Paskevic

Hello everyone! Guess what? Partials are over! That means that today we're back on track... And today's topic is libraries, a.k.a. modules in Python.

Let's begin by defining modules. TutorialsPoint defines a module as a logical way to "organize your Python code. Grouping related code into a module makes the code easier to understand and use".1 In short, a module is a separate file where you define functions related to a specific action and then import it to your code. The best thing about it all is that it makes coding less confusing and functions re-usable across several programs!

Let's get started!

Creating a module

Creating a module is easy. All you have to do is create a new Python file and define the functions that will belong to that module.2 For example, if you wanted to create a module containing all the functions for Tic Tac Toe, you would create a module named tictactoe and define all the functions inside.

Using a module

Once you wanted to use the library you just created or downloaded from the internet, the first step would be to import it. In the file where you will use it, type the word import followed by the name of the module. Let's say we wanted to import the tictactoe.py module we imaginarily created above:

import tictactoe

That imports the module, but in order to use the functions inside it, you need to call the function by using the name of the module (dot) name of the function. Let's say I wanted to use the newGame function within the tictactoe module:

tictactoe.newGame()

That's it for today... I know, that was easy! Happy Mexican Independence Day! ??

@emamex98

--

Library

--Originally published at Hackerman's house

A library is a built-in module that can be used to solve several problems. Once python is installed it includes a series of standard libraries such as math that can be used to solve mathematical problemas or generally just to work better with numbers. There is also the time library to count the time. You can find more information about it here.

https://docs.python.org/3/library/

In this example we’ll be importing the “math” librarie to calcule the area of a circle, the radius will be given by the user and the program will substitute this number in a formula

Import a librarie is simple, the syntax is this:

import name_of_the_library

And the functions included in every library are different, these functions can be find in the link above.

The functions of math that we’ll be using is the pi value.

libraries

The “try” and “except” are used to determine if the input given by the user is a number. The radius is given by the user and the area has a simple formula PI times radius square. That is why we needed the math module.

Here is how the program works.

libraries2

Thanks for reading me.

giphy-5


FOR ALL THOSE PROCRASTINATORS

--Originally published at Coding The Future

If you are reading this right now, you were probably procrastinating, and just started studying for tomorrow's test, right?

Well, as always, I've got you covered. Here's a quick video summary of what you need to know for the first partial. I hope things are not too strange.

Good luck!

Modules and libraries

--Originally published at Py(t)hon

This time we are going to see the Modules or Libraries what are those things, in simple terms they are Python files that contain definitions and statements, this ones can be imported or well created by yourself.

To import one of this modules and use it in your program is very easy, you just type “import” follow by the name of the python file (without the suffix .py). Then when you are going to use it for pi or cos(x) you have to first type the name of the module, then the pi or the cos(x). Here is an example:

modules 1

With the previous function we did with the help of the module math, we are going to use it as a module:

modules2

That’s the basic of modules and libraries, see you next time. Here i leave you a youtube tutorial maybe you understand it better with this video. #Pug#Python#Modules#Libraries#Tc101