Quantcast

A community for students. Sign up today!

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

JonathanFichter

  • 3 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.

  • This Question is Closed
  1. ewsmith
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 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. JonathanFichter
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Great answer. Thanks!

  3. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Ask a Question
Find more explanations on OpenStudy

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
  • 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.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.