+ 3

Is there any difference between 'import math' and 'from math import *' ??

24th Jun 2020, 9:33 AM
Vasudev Dubey
Vasudev Dubey - avatar
5 ответов
+ 12
If you use "import math", you can use math functions with a dot notation math.sqrt, for example, x = math.sqrt(4) If you use "from math import * ", all math names are available without the dot notation. They've flooded your namespace, and many conflict with function from your, or other modules, namespace. You can call the square root function "directly" : Example: x = sqrt(4)
24th Jun 2020, 9:47 AM
𝚂𝚊𝚗𝚍𝚎𝚎𝚙 🤍
𝚂𝚊𝚗𝚍𝚎𝚎𝚙 🤍 - avatar
+ 2
There is: import math math.sqrt(4) from math import * sqrt(4)
24th Jun 2020, 9:49 AM
Aleksa Kis
Aleksa Kis - avatar
+ 2
Yes, in the way its methods are called. When you use: import math The syntax for using a math module method (say that 3 times fast) is math.<method>() |example| math.sqrt() When you use: from math import * All you need is the method. So... sqrt() Would be the call if you imported everything from math
24th Jun 2020, 9:50 AM
Slick
Slick - avatar
+ 1
Thanks buddy🤓
24th Jun 2020, 11:35 AM
Vasudev Dubey
Vasudev Dubey - avatar