hello guys in this blog I am going to show you how to use built-in modules and functions in Python so if you have remembered that in the previous blogs I have shown you how to calculate the exponent of some value so for example I want 2 to the power 3 I can use 2 and then these two Asterix and then I can write 3 and this means 2 to the exponent 3 and gives me the value of 8 ok but there is a easier way of doing the same thing and this is by using a building functions which are provided by - so what R is a function first of all if you are new to programming a function is a piece of food which executes some function or some logic ok so a function is a piece of code which executes some logic so for example you want to calculate the exponent of 2 like this you can do it like this or you can use a built in function which executes of exponent function right so you can use p or W which is power and this function takes 2 arguments first is the value which is 2 and then the exponent which is 3 or this means 2 to the power 3 it also gives you the value 8 which is same and it's more easier to use this and it's more easier to understand this expression rather than this because it's more descriptive right now how do you know that what are the built in function in Python ok so if you don't know what are the built in function there is a command to know what are all built in functions in pipe and what is this the man this command is you just need to write di R and then give these two brackets and this two brackets just write double underscore and then just write built-ins and then double an underscore once again and you just need to give this command and what this command just press ENTER and what this command will return this command will return all the built-in functions which you can use in Python okay so for example I was using P or W which is a power function and you can find this P of W function here okay this is the power function so you can see you can calculate hacks there is a function called abs with to calculate absolute value so for example I want to calculate I will use a be s and I will write eighteen point six six six six and press ENTER it gives me the absolute value of ABS this should be it will be different I think it should be like this and okay so it give me the absolute value of the number okay or you can use this print to print something or you can find this le n function to find the length of a string so I can use le n and give some strings for example I can write hello which is a five letter string 1 2 3 4 5 right and this length will return the length of this word which gives 5 right so and there are some other useful functions like minimum max simoom slice so these are all the built-in functions in Python now once you know the function that okay this function exists here now how you can know that what is the functionality of this function right so to know the functionality of the function what you need to do you can use a built-in function called help that's help okay so for example you want to know what this function called Max does okay so what you can do you can just write help and then in the brackets you can just write the name of the function for example you want to know what this function Max does you just write help and in the bracket just write max okay and press ENTER and this max you can see here so this helps is that this Max is a function which can take more than one argument multiple argument and it gives the I think maximum value of those arguments right so you can see it with a single it readable argument returns its largest item okay so now I know that when I use a function called Max and I can give multiple argument for comma 2 comma 1 comma 5 comma 8 and when I press ENTER it give me the maximum value which is 8 right so in this way you can use this help function to find out what these other built-in function does or what is the use of these written functions right now this is about the function of built-in function now there is something called built-in mod okay and these built-in modules are the extra modules which contains extra functions or extra functionalities which you can use whenever you choose or whenever you you include these modules so for example you want to know or you want to calculate the square root of some value so there is a module called so for example you want to know the square root of something so
there is a module called the math you can use it for this so to include a module you need to import this module and how you can import the slide import and this is the key word to include the module and then the name of the module which is for example math in our case and when you press ENTER now you have included this module now how you can use the function inside this module you can just you write the name of this module which is math dot and then you can use all them you can see there are different options with you which you can use with this module called math you can see here right so whenever you write dot can you give you some options you can see and this options you can scroll it by up and down keys okay so this math module has these much amount of built-in functions right you can scroll up or scroll down and what function I am you I want to use I want to search for square root so there is a square root here okay so I can use square root I have press ENTER so this gives me some values of the once again math dot s Q R T and then I can find the square root of any number for example I want to find the square root 9 will give me the answer 3 so in this way there are some built in modules also and this these Wilton mod will also have some function built-in functions and you can import these built-in modules using a keyword input and the name of the module and then you can use these modules like the name of the module and the function which it contains now sometimes these modules are you know hard to you know spell all right so what you can do you can define your own variable for these modules names for example I can declare a variable called square root which is equal to this math dot s QRT okay now whenever you use square root variable you can perform the same functionality for example I want to find out the square root of 9 it will give me 3 so you can replace these built-in functions in module by your variable using this equal to sign ok and now you have your own variable which can calculate the square root or any other function so in this way you can use built-in modules and built-in functions in Python I hope you have enjoyed this blog
Post a Comment