Got Homework?
Connect with other students for help. It's a free community.
Here's the question you clicked on:
 0 viewing
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.
 2 years ago
 2 years ago
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.
 2 years ago
 2 years ago

This Question is Closed

ewsmithBest ResponseYou've already chosen the best response.0
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.
 2 years ago

JonathanFichterBest ResponseYou've already chosen the best response.0
Great answer. Thanks!
 2 years ago

bwCABest ResponseYou've already chosen the best response.1
http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html#importing http://docs.python.org/howto/doanddont.html#idiomsandantiidiomsinpython
 2 years ago
See more questions >>>
Your question is ready. Sign up for free to start getting answers.
spraguer
(Moderator)
5
→ View Detailed Profile
is replying to Can someone tell me what button the professor is hitting...
23
 Teamwork 19 Teammate
 Problem Solving 19 Hero
 Engagement 19 Mad Hatter
 You have blocked this person.
 ✔ You're a fan Checking fan status...
Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.