Universal Imports : Plzz explain difference of code in import module


Replace this line with your code.


Hi Friends, hope you are doing great :slight_smile: plzz tell me difference between the below two statements:

1) from math import *
// I think this will import all functions of math

2) import math
//from my understanding this statement will also import all functions of math

if my understanding is correct then is it that there are two ways of doing same thing or both are used in different conditions.



they are different, if you do this one:

from math import *

Now you can use for example factorial (a function in the math library):

from math import *
print factorial(3)

however, this is potential dangerous, given your own function or more imports, which is why this is recommended:

import math
print math.factorial(3)

now, there is less change of name conflicts (functions with the same name).


thanks :slight_smile: I got this cleared :slight_smile: