So after the Computer Science Fundamentals course I decided to take the Python course as a compliment to the Java program I'm already learning at school. I have a question about the whole drawing thing. It tells me that to import the turtle you have to type in "from turtle import *", to move forward you type something like "forward(300)" and to turn left a certain number of degrees you type "left(45)". I tried compiling the code on an online compiler (onlinegdb.com). It didn't work. I then tried downloading Python for my computer, and it didn't work as well. When I tried to find the code online, it gave me a different format on how to do everything. For example, if you want to get the turtle into your Python you write "import turtle" instead of "from turtle import *", to move forward you write "turtle.forward(200)" instead of "forward(200) and to turn left you write "turtle.left(45)" instead of "left(45)". This may discrepancy may be tiny or it may be huge, I may just be really dumb and this different syntax's be something common in computer science. But I'm new to most computer science concepts, so if anyone can explain to me why this is the case and which one is correct it would be very much appreciated. :)
Easy Math Editor
This discussion board is a place to discuss our Daily Challenges and the math and science related to those challenges. Explanations are more than just a solution — they should explain the steps and thinking strategies that you used to obtain the solution. Comments should further the discussion of math and science.
When posting on Brilliant:
*italics*
or_italics_
**bold**
or__bold__
paragraph 1
paragraph 2
[example link](https://brilliant.org)
> This is a quote
\(
...\)
or\[
...\]
to ensure proper formatting.2 \times 3
2^{34}
a_{i-1}
\frac{2}{3}
\sqrt{2}
\sum_{i=1}^3
\sin \theta
\boxed{123}
Comments
Hello Okky, Let's kill this topic together. Let's say you have written a file named math.py and you have written two custom functions in this file namely pow(a, b) and round(a). And you want to make use of these functions in a new python file named main.py. Now you have two ways to do that 1. import math and then use functions like math.pow(a, b) and round(a). 2. from math import math, round and then use functions like pow(a, b) and round(a).
Also from math import * imports everything that was defined in math.py. But this is not used as it hinders production level code development. For example: Suppose that you have two independent modules math.py and math1.py. Now, math.py has a custom function subtract that takes in two arguments (a and b) and return a - b. What math1.py's subtract does is return (b -a). And you import both files in main.py .Then you will get an error that function definitions are common.
I think you must ask programming related questions on StackOverflow. Read this great answer: https://stackoverflow.com/questions/710551/use-import-module-or-from-module-import. Also read the official documentation here: https://docs.python.org/3/tutorial/modules.html
Log in to reply
I think I get it. So from module import * imports everything that is in math.py, while import math only imports the functions?