hey guys welcome to the next blog on Python tutorial for beginners in this blog we will discuss about built-in functions and modules in Python so the Python interpreter has a number of built-in functions modules and type that are always available that means you can use them at any time and we have already used some of the built-in functions in Python so first of all we have used the print built-in function we have already used the input built-in function we have already used the int which is used to typecast a float or a string into an integer right we have already used a built-in function called float which is used to convert an integer to a float value or a string to a float value now python has a list of these inbuilt function and you can find this list by going to the Python dot o-- r-- g-- website and then clicking on that docs section and you can choose the version you have installed so we have installed the latest version which is 3.7.0 and you can even choose your language which are available here now when you click on this link which says library references you will be able to see this page which says Python standard library and then when you scroll down here you will be able to see the introduction about Python and the second section here is about built-in functions so I'm going to click on this built-in function link and here you will be able to see all the built-in functions in Python so this is the list of all the built-in functions which you can use in python and if you want to know more about these functions for example I want to know what this max function does I can click on this function and then you can get the help about this function so what this function does and how it can be used in Python all the information is given here now let's go to the terminal and let's see how we can use some of these built-in functions so first of all how you lists out all these built-in functions and types in Python there is a built in function to list out all the built-in functions and types which is dir and then double underscore and then you write built-ins and then once again double underscore and then close the parentheses and then press ENTER and it's going to give you the list of all the buildings available in Python so for example from this list we have already used this function called float print and then we have already used this function int and input also so let's use some more functions so in the previous blogs I have shown you how to calculate the power of a number so you use these double asterisks in order to calculate the power of any number and you can see you get the power of 2 to the power 10 now Python also have a built-in function called P or W here you can give as a first argument the number and as the second argument you can provide a number which you want to use as a power and when
I press ENTER it gives me the same result let's use some other built-in function for example le n le n you can use to find out the length of any string so I can write le n and inside the parentheses I can just write any string here for example hello and it will give me the length of the string so this string hello have five letters inside it that's why it's giving me length 5 now there is a built-in function called help using which you can get some help about any function so I can write help here and inside the parentheses I can just write the function name so for example I want to know what this max function does so I can just write max here and then press Enter so it gives me the signature of Max so how it's used and then it will provide me some description about the function so what it does so you can see here it returns the biggest item right so I can just write here and inside the parentheses I can give the list of items here for example 1 2 8 9 4 & 5 and when I press enter is going to give me the maximum value out of this list so you can use this help built-in function in order to know more about all the other built-in functions now till now we have talked about the built-in functions which are available in Python now let's talk about some of the built-in modules which are available in Python now what is a module I'm going to describe in the later blogs but for now let's see how to import a built-in module in Python and how to use them so there is a built-in module called math and to import it you just use a keyword called import and then the module name for example mat and press enter and it's going to import this module into our interpreter now you can use this math keyword and then you can write dot and wait for some seconds and you can see it gives me all the lists which are available inside this math module so let's say I want to find out the square root of any number I can use a function called sq RT here and then this gives me the square root of a number so for example I want to find out the square root of 100 and then press Enter it gives me the answer 10 now once again as I said you can use a built-in function called help in order to know the signature of this function so I can just write Matt dot s Q R T and then press ENTER and it's going to give me some help about this function so you can see it returns the square root of x and the signature looks like this now if you want to print all the methods and types available inside this built-in module you can once again use this built-in function dir and then in the parentheses right the name of the module so this time we will write math here and then press ENTER and it gives me the list of all the available functions available inside this math module and you can see all these functions which are available inside this module so you can just use a cost function from here PI function from here radiance or tan function from here so this is how you can use built-in functions and modules in Python I hope you've enjoyed this blog
Post a Comment