I'm getting the rough sense that there's a difference between entering "import math" and "from math import *", but I'd love for someone to explain it to me more fully. The problem set told us to do the latter, but I had to also do the former in order to get square roots to work. To me, this was puzzling.
The statments do similar things but have different scoping. sqrt() is a method (function) in math. If you use "import math", to use the square root function you will need to call it with math.sqrt() If you use "from math import sqrt" you can call the function with just sqrt(). The "*" is a wildcard so with "from math import *" you are importing all of the methods in math. Both methods have there place. For smaller problems such as the homework assignment "from math import *" makes using sqrt() less typing. But if you are already using the name sqrt() to mean some other function than using "import math" avoids naming conflicts.
Great answer. Thanks!
Join our real-time social learning platform and learn together with your friends!