0
* imports all objects from a module like from math import *. But import math also imports all objects right?
2 Respostas
+ 12
# The difference is that with 'from' you can use those methods directly, without the module name.
# 1.
import math
print(math.sqrt(9))
# 2.
from math import *
print(sqrt(9))
# 3.
import math as m
print(m.sqrt(9))
# 4.
from math import sqrt as s
print(s(9))
0
I would add that the "from module import *" is not recommended (see PEP 8). It is usually better to simply use "import module".