Open study

is now brainly

With Brainly you can:

  • Get homework help from millions of students and moderators
  • Learn how to solve problems with step-by-step explanations
  • Share your knowledge and earn points by helping other students
  • Learn anywhere, anytime with the Brainly app!

A community for students.

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.

MIT 6.00 Intro Computer Science (OCW)
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Join Brainly to access

this expert answer

SIGN UP FOR FREE
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!
http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html#importing http://docs.python.org/howto/doanddont.html#idioms-and-anti-idioms-in-python

Not the answer you are looking for?

Search for more explanations.

Ask your own question

Other answers:

Not the answer you are looking for?

Search for more explanations.

Ask your own question