+ 3
Is there any difference between 'import math' and 'from math import *' ??
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)
+ 2
There is:
import math
math.sqrt(4)
from math import *
sqrt(4)
+ 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
+ 1
Thanks buddy🤓