+ 2

How to use import math in python

5th Jun 2021, 5:12 AM
Shan Kumar Singh
Shan Kumar Singh - avatar
11 Réponses
+ 7
Python has also a built-in module called math, which extends the list of mathematical functions. To use it, you must import the math module: import math And use it like: math.sqrt(4) or the famous: math.pi
5th Jun 2021, 5:17 AM
Dino Wun (Use the search bar plz!)
Dino Wun (Use the search bar plz!) - avatar
+ 2
Or use can import like this: from math import * sqrt(4) pi
5th Jun 2021, 6:12 AM
Eashan Morajkar
Eashan Morajkar - avatar
+ 2
import math print(pow(3,4)) #Can use like this too
5th Jun 2021, 6:57 AM
Atul [Inactive]
+ 2
Eashan Morajkar Is ceil function too works like that?
5th Jun 2021, 7:34 AM
Atul [Inactive]
+ 2
Eashan Morajkar ok this will work import math print(math.sqrt(25))
5th Jun 2021, 7:38 AM
Atul [Inactive]
+ 2
Eashan Morajkar just check the sqrt case pls
5th Jun 2021, 8:10 AM
Atul [Inactive]
+ 2
Yes so the second one is correct, isn't it?
5th Jun 2021, 8:13 AM
Atul [Inactive]
+ 1
Atul That's not a math function use can use pow function without math print(pow(3,4))
5th Jun 2021, 7:01 AM
Eashan Morajkar
Eashan Morajkar - avatar
0
@Atul ceil function requires the math module
5th Jun 2021, 8:03 AM
Eashan Morajkar
Eashan Morajkar - avatar
0
Atul Your sqrt case will work because you're importing the math module and it will print 5.0
5th Jun 2021, 8:11 AM
Eashan Morajkar
Eashan Morajkar - avatar
0
Atul yes it will
6th Jun 2021, 3:58 AM
Eashan Morajkar
Eashan Morajkar - avatar