Hello and welcome to this video.
What are built in modules built in modules the modules that Python has already created for you before
you can use the built in modules you need to use the import statement to access them.
I'm going to show you a couple of example modules that are built in that we can use.
The first one is a module called random.
This module is basically used to generate random numbers.
We can use the module we have to import it.
So you do that by using the input statement which is import and then type in the name of the module
the module is called random and it is used to generate random numbers say for example have a variable
called X and set it to equals two random random being the module.
So what this code on line 3 is basically X is a variable I created an offset to close to the module
random and inside that module random I am using a function called random.
All right.
So what I can do I can print this out on the screen by using a print statement.
I can just say print inside the print function I can pass in X which is the value of this which is this
x variable which would give me a random number.
So let me click on the play button I can see here is giving me a random number if I click on play again
the number will change because it's giving me another one.
If I click play again it changes the number.
It generates the number it has generated is basically a float so a float is a number that has decimal.
Now inside this module called random it has all the functions as well that one can use.
One of them is called round INT.
What that does.
It can round numbers into an integer which is a whole number.
So if I want to say generate a number that will be a whole number I can for example create another variable.
If I want to say I just created variable Y and I'll just set it to equals to random which is a module
I do a dot and then from that module random I'm going to use a function called a round int which is
what will convert whatever random numbers generated into an integer.
So I'm going to pass in to values 0 and 50 so what I will do is to generate random integer number from
0 to 50.
So for that to happen I need to add a print function I'm passing the variable y into that print function.
Now let me play this and then you can see.
So this is the first one.
That's the first print on line number four where it generates a random number which is a float and their
line number six here is the way I use the front end function.
Line number seven.
I'm telling you to print.
Why so does it there.
So what does it generate a random number then convert it into an integer.
So any random number between 0 and 50 see if I click play again it will give me a different number this
time I can say is given me forty seven so any number between 0 and 50 so when you reusing the rand end
you can always specify the range you want it to generate from there's another module I want to quickly
introduce you to is called the platform module is used to basically detect what platform your system
is running on.
So to use it again we need to import it so I type in import space followed by the name of the module
is called platform.
So now that I've imported it I can use it in my file.
So I'm just going to create a variable called J.
And I'm going to set it to a course to platform dot.
So from the platform module there's a function called system.
So I'm using that function code system and I'm just going to attach a print statement as I say print
on a passing the variable j.
Now if I print that issue tell me what platform I am running on so I click on play.
I can see here it says windows.
All right.
So if you're on a Mac you should say Mac and so on.
So that's how you can use beauty in modules you first of all have to import them and then you can access
either different parts from that module that you want to use.
So that's it.
Thanks for watching.
And bye for now.