- Podcasts
- Python To You
- _15 Python Tutorial for Beginners _ Import Math Functions in Python
_15 Python Tutorial for Beginners _ Import Math Functions in Python
Python To You
- October 17, 2026
- 8 min
About this episode
No description.
Transcript
From the publisherThis transcript comes from the podcast’s own feed, shown as the publisher wrote it.
_15 Python Tutorial for Beginners _ Import Math Functions in Python
Welcome back aliens, my name is Devind Reddy and let's continue with this series on Python. So till this point we have seen a lot of stuff in Python right and now it's time to look at mathematical functions. Now of course we can do that manually as well right you can find a square root of a number, you can find a square root of a number as well but then we can use mathematical functions then why to do it manually. Now let's try something. So what I will do is I will do some simple stuff. So how do you find a square root of a number? It's very simple actually. You just need to say x equal to I want to find a square root of 25. So it's very simple. In Python we have an inbuilt function called a square root which is sqrt and in this bracket you just have to pass the number which is 25 in this case. I will say enter. Oh we got an error. That's bad. Maybe spelling mistake. No, it is SQRT, that's right. What went wrong here? The thing is, in Python, we have a lot of modules to work with. Now, these modules are by default not there for you. Now, if you want to use them, you need to ask for it, right? So we are living in a world where you need to ask for things. Now, how do you ask for it? the way you can ask you can import it with the help of import of course and then you have to say import and then you have to mention a module name here called math so math is a module in which you have all these functions i will say enter okay that's done right so we got we got all the functions now and And now you can say x equal to math.sqrt and then you can find 25. Oh, it works. Okay, there is no error. So we got our value in x now. Let's print x and that's right. We got 5.0. Yay, it's working. fact we can try it with different values here now so i will say 15 x and that's the value of square root of 15 right so it's working now we have some other functions as well example one of the functions which we can use here is called as floor function now how floor function works let's say we have a value which is y in fact i will print it i will say print i want to print floor function value so i will say math dot So we have this concept of seal and floor. So what it means? Imagine you have a value which is 2.5. So normally what we do is we try to round off these numbers, right? For example, I don't want point values. I want the integers. So in normal world, we round off these values. We say, okay, when you have 2.5, we'll make it 3. And let's say if you have 2.4, we'll make it 2. So anything which is less than 2.5 will be 2. Anything which is greater than or equal to 2.5 will make it 3. That is round off, right? But we want to use float and seal. So imagine this is 3 and this is 2. So when you say 2.5, it will be somewhere here. So when you say 2.5, you will make it 3. When you say 2.4, you will make it 2. But then instead of using roundoff, we can use floor. So we have floor and we have seal. Now when we use floor, it simply means you need to go to the floor. Imagine this is floor. We have floor and we have seal. So here we have a floor and then we have seal. So when you apply a floor function, it doesn't matter what your value is. Even if it is 2.9, you will get 2. Right, that's floor. Now what about seal function? Example, if I say seal... of 2.1 so if you say round of it will be 2 right but when you apply seal you will get 3 right let's find it out so when you say i want to find floor of 2.9 you will get 2 the same thing can be done for seal so you say seal of 2.2 you got 3 right so floor will always give a last the least value and seal will give you the highest value highest integer So likewise, we can do factorial, we can find sine x, cos x, you know, all your mathematical functions. In fact, there is one more. We also have power, you know, P-O-W. Remember, we have done this calculation, which is 3 into 2, 3 squared, right? So you got 9. The same thing can be done with the help of power function. So when you say, I want to print, let's say, math.P-O-W, which is power function. And here you will say 3,2. Now you can see we got nine. So this is it will give you power. You have two choice. You can use double star which is power again and then you can also you can also use power function. But now when you work on big softwares it's always better to use functions because it's more readable for the developers. Right. And then in math, we have some constants as well. It's not just about functions. Example, let's say I want the value of pi. We all know it, right? It's 3.14. Not exactly. After 3.14, we have some more values. And no one remembers that, right? So what you can do is you can say print and I will print math.pi. And that's your pi value, right? So we have some more values there. We can also get the value of epsilon. So you will say math.e, and that's your epsilon value. So those are constants which are available. What if you don't want to use maths every time? Because, see, we have a lot of modules, right? And some module names are very big. And we are damn lazy to type those names here. So instead of using math, can I simply use m.sqrt? Well, that will be good, right? m.sqrt. But unfortunately, it will not work. So if I say enter, you can see it's not working. So in that case, if you want to use m, we need to use a concept of allies. What it means? So when you import math, say as m. So what you're doing now is you're saying, hey, I'm importing math. But whenever I want to use math, I will be using m. Or I can use m or math both. So let's try with math first. Is math is working? So I would say 25. Okay, math works. Same goes for, let's say, let's try M. 25, even M works, right? So your choice, you can use M, you can use math. So whenever you have big names or if you're lazy to type even math, you can try allies, right? Okay, now we have one more thing, you know. So let's say you, in your math module, you have so many functions available, right? So we have so many functions, classes available. And the moment you say import math, you get everything, right? What if you don't want everything? What if you want things which are specific? Example, I only need power function. I only need factorial. I don't want everything. So in that case, what you can do is you can say math. So when you say import, in fact, let me just reopen my IDE so that, in fact, we can restart. So I restarted this shell here and let's try. So I will say math. dot sqrt 25 you can see we got error that means it's not imported so now i will import but then i don't want to import all the functions i want to import let's say sqrt and power that's it so we'll say from math so to mention we want to import from math so we'll report only two things one is sqrt and power that's it give a comma and give say power and you can see there's no error let's try so i would say in fact now you don't even need to specify math because you have imported the function itself so i will say power of four raised to five i don't know the value maybe maybe it's right so it's one zero two four that's right it's actually right answer so it works you know it works so that's that's how you work well that's how you work with mathematical functions so you can try it out there are so many functions available so just go to documentation in fact we'll search here So you can see when you search for math, you have so many functions available here. Read documentation and try it out. So the best way to learn something is to do some research, right? So after watching my videos, make sure you read some book or you do this research. And that's how that will make you a good programmer. So I hope you enjoyed this series. Let me know in the comment section. And if you have not subscribed the channel, what are you waiting for? Do subscribe it. Bye-bye.
