+ 1
From math import * & pi
from math import (pi, sqrt) print(pi,sqrt(4)) # how to make the answer appears one the next line instead of side by side and about this from math import * do we have to use print afterward or how? Thanks
12 Answers
+ 3
For your first question, you could add the \n operator to indicate a new line between the two inputs, putting the result of the calculation of the square root of 4 on the next line:
print(pi,"\n",sqrt(4))
For your second question, importing * from a module basically just indicated that you're importing absolutely everything from within that module into your code. Because of that, it is very similar to importing specific functions, like you did in your first example, and does not need to do anything specific afterwards.
Hope this helped! d:
+ 1
Medo Hamdani Of course! In no code is there really something mandatory for you to do, so using the print function is absolutely optional in any code, although it is an easy way of displaying text into the console.
+ 1
Faisal
when this code is used
from math import *
the output will be like
no output
is that what is supposed to happen
+ 1
Medo Hamdani Well, because you are not outputting anything into the console, that is definitely what is supposed to happen :)
+ 1
thought the point of this is to get the whole list of all objects related to math module. Like if you remember the *.* in MS word
+ 1
Well, not exactly. The point of the import function is to import other functions/classes from specific modules into your code and allow you to use them. It does the same thing as specifically importing things directly from a module, but it just allows the use of everything from within that module into your code.
For example, say you wanted to use the re module. If in your code you only wanted to use the search function, then you could specifically import only that to allow for the use of it:
from re import search
This allows for the search function from the re module to be used, as not doing that would just raise an error if you tried using search.
If you wanted to import everything from the re module, then you could use the following line:
from re import * #import re could also do the same thing
This allows for you to use any function, class, etc. that the re module provides, and gets rid of the need to individually import them all separately.
+ 1
Well, there shouldn't be any output as you are merely just importing the search function, which doesn't output anything. It only just allows for future use of said function.
+ 1
thank you for your help
this code which I meant
from math import (pi, sqrt)
print(pi,"\n",sqrt(4))
import math
print(dir(math))
0
thanks Faisal , but would from math import* works without print something line
0
yes, time to test
0
from re import search
no output !
same to math
- 1
Let me test it.