Home>Article>Backend Development> The difference between from module import and import
I am using codecademy to learn python recently, and I encountered some mistakes in the questions. I will record them briefly
For example, from math import sqrt imports sqrt as the method of this file. When using it, you only need to call sqrt directly.
And if the import is import math, then the method of math.sqrt must be used when calling.
So what if a function with the same name is defined in your own file? Let’s try it out
Python code
from math import sqrt def sqrt(n): return n print sqrt(13689) raw_input()
Run the py file and output 13689, so the function you defined will be automatically blocked.
So it is a better way to quote import math.
In addition, python does not support import math.sqrt like java