7 Antworten
+ 5
Are you talking about this.
from math import *
if yes then here * is used to import all available functions in math module.
+ 5
Muhammad Abdulmalik
when you use
import math
you have to use math.function_name() syntax to use the function like
print(math.ceil(9.754))
When you use
from math import *
Now you imported all functions of math module . you can now use function name directly like
print(ceil(9.544))
+ 4
Muhammad Abdulmalik ,
instead of importing a complete module, you should only import the functions / classes that you really need.
sample: you need to round up a number to the next whole number, and you also need the square root function you can do:
from math import ceil, sqrt
+ 4
Lothar Yes... yes... yes... I 100% agree.
I actually meant to point that out as well and got distracted.
Thanks for stating this. 👌
Ultimately, using * will pollute the namespace and increase the risk of name collision.
+ 3
I agree with the answers from SAYED🇧🇩🇵🇸.
If you want to read more on this, here are a few links I recommend:
Guru99 Link:
https://www.guru99.com/import-module-JUMP_LINK__&&__python__&&__JUMP_LINK.html#8
Medium Article:
https://python.plainenglish.io/understand-python-import-module-and-package-c5b4289bbf60
RealPython Link:
https://realpython.com/python-modules-packages/#from-module_name-import-names
Scroll down slightly until you see the example:
from <module_name> import *
If you're interested in digging deeper with understanding how this works building your own package, the following link would be worth reviewing:
https://realpython.com/python-modules-packages/#importing-from-a-package
+ 1
Muhammad Abdulmalik
* used for multiplication. You didn't see in lesson how to use and where to use?
Are you talking about unpacking lesson where * is used?
https://www.sololearn.com/learning/2485/
0
SAYED
pls can you give an example in order to understand clearly......thanks for you comment.