0

What are uses of * module in python and how can I use it ?

Python

16th May 2021, 4:39 PM
Muhammad Abdulmalik
Muhammad Abdulmalik - avatar
7 Answers
+ 5
Are you talking about this. from math import * if yes then here * is used to import all available functions in math module.
16th May 2021, 4:54 PM
TOLUENE
TOLUENE - avatar
+ 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))
16th May 2021, 5:06 PM
TOLUENE
TOLUENE - avatar
+ 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
16th May 2021, 8:30 PM
Lothar
Lothar - avatar
+ 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.
16th May 2021, 9:33 PM
David Carroll
David Carroll - avatar
+ 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
16th May 2021, 5:25 PM
David Carroll
David Carroll - avatar
+ 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/
16th May 2021, 4:42 PM
AÍąJ
AÍąJ - avatar
0
SAYED pls can you give an example in order to understand clearly......thanks for you comment.
16th May 2021, 5:02 PM
Muhammad Abdulmalik
Muhammad Abdulmalik - avatar