Hello everybody.
And welcome back.
And right now let's see how we can actually import some oil or some of the older the used libraries
that come in Python.
So let me just throw this.
You might have noticed that sometimes in my Python interpreter I actually clear my screen now that he's
using the input function which actually imports the OS library which allows me to run a terminal commands
in my program.
So let me just show you how you can do that so you can just type your anything.
Doesn't even matter.
And then once you want to create for example the screen you can just import the OS which is the library
for the operating system and then you can just use that or use the functions in that library to create
to clear the screen.
So one of them is always a dot system which basically in this always in this OS library uses a function
called system which specified in the brackets specifies the command that we want to run.
So in my case clear and wants a president you can see that it actually clears the screen.
You can also run any other command doesn't have to be clear so you can just type your unless and you
can see that will it will actually list all the files in my current system directory or part of I mean
my current python programs directory which are these six programs.
So these can be also useful for us.
That is a simple use of importing a library.
Now you can also do something like this.
So let me just close this nano import import by let's actually call it along.
Let's save it.
Not knowing why we actually type here.
User when I write on.
OK.
So right now we can add a simple function which is called adding num number one and number two.
Now this is just a function that will add two numbers and store it and print the result of those two
numbers so print and online plus name two.
Well let's put it as an integer so it should print the integer of these two numbers so let's do it like
this.
Now basically you can just save this file just remember the name of the function which is adding You
can save it.
And we can see if I see it's not that important why this program doesn't really do anything it just
closes runs the program doesn't print out anything and then closes the program.
That's because we only have one function in it.
But let's now run our normal program.
So let's not on Python 7 by user being python and let's import our import.
Now that could be a problem since our import is called import.
So let's actually rename it.
I thought that would be a problem.
We control though let's call it I m b r t so we can actually depreciated from the command import itself.
So finding the right.
Yes and then we close.
So right now we have once again.
OK.
So we remove the import function by or pardon me the import program the pie then when we see mode the
import apply.
And now we have our imports by with a simple adding function that we want to use in our other program
which is Python 7.
So let us open five to seven by now let us continue.
So right here you can basically just do this.
So a equals the raw inputs and we want to integer right here since we want to specify a number so first
No this is something that we already covered the equals integer raw input.
Second number.
And right now all we have to do is specify adding a map a comma B.
And right now what we have to do is import input and then we can use the function that we specified
in a different code by Cat by 10 7 vote buying or to see if everything you said correctly we have our
adding function from a different program which is by the user input for two numbers.
And we imported our library which is this program right here.
So right now all they have to do is see each month despite seven to be an executable and we can run
it by seven so three three named adding is not defined.
Yes of course I forgot.
So right now in order to use this function you actually have to specify the name of the file itself.
So you cannot just use adding since that would be a function that is defined in this program went to
specify from which library or from which program we use this function and in our case we use it from
the from this function.
So we have to specify down here input dot adding which will report to so python will know that it should
look for this adding function in this library right here that the three important that we imported.
So just delete this and let's save this right now.
And right now it should work.
So Python 7 3 4 and we get 7 as a result as we can see we were able to use a function that we didn't
use in our own program in order to execute a simple adding of two numbers.
So that is how it functions.
Me That is how important works.
And that is why it is so useful.
So basically we can use any program that anyone before us called it and we can use the functions from
those programs in order to help us build our own program faster or basically if someone already coded
something that we need we do not have to code it ourselves we can just download that program and use
it as we like.
So that will be about it for the importing libraries.
It is very simple so you just find a library you want to import.
You need to put it into the same directory as your program and then you just type up her up at the beginning
of the program import and then the name of the library.
After that you need to specify any function with just the name of the library dot and then the name
of the function.
So pretty simple.
So that be about it for this tutorial in the next one and probably the last line of Python basics.
We will cover the creation of files which is something important we will learn how we can create files
delete files right to files and read from files.
So that would be allotted for this tutorial and I hope I see you in the next one by.