Import math vs from math import *, is there a difference?


I was just wondering if there is a difference between "import math" or "from math import *", is there?

import math

will import the math module. Any functions that you use would have to be used as math.sqrt, math.ceil, etc.

from math import *

will import all functions from math. Any functions that you use can be used as sqrt, ceil, etc.


Think of math as your refrigerator.

If you import the refrigerator (import math), you will need to open the refrigerator door to take out the food and bottles, like, refrigerator.bottle.

But if you import everything inside the refrigerator (from math import *), then that means you can freely use the food and bottles as they have already been taken from the refrigerator and outside it (so, no need for, just use food).


Thanks! I love the analogy.