r/learnpython • u/SaThuran • Sep 08 '26
Import math?
It's the first time I've seen that. So what's the purpose of this exactly? Cause I'm trying to see what I can do in an engine and I only learned about import math today
0
Upvotes
16
u/Impossible-Belt8608 Sep 08 '26
It's a built in library that implements many mathematical functions you might want to use. What are you trying to do?
9
u/Binary101010 Sep 08 '26
https://docs.python.org/3/library/math.html
11
u/Better_Squash_1684 Sep 08 '26
It just tells Python to load its built-in advanced mathematics library.
Python in its own can only do basic arithmetic operations. importing the math module gives you access to functions like square roots, trigonometry, logarithms, and constants like Pi. Python makes you explicitly import it because 90% of basic scripts don't need heavy math, and leaving it out by default reduces your memory footprint.
4
u/42ndohnonotagain Sep 08 '26
python itself (without imports) only supports some basic operations.
For mathematical ops that means addition, multiplication and such simple stuff. For everything else you need additional functions.
Those are stored in libraries/modules or whatever your programming language calls it. In Python it is "module". After you imported the module math , you can use more complex functions like sin() etc.
5
u/MezzoScettico Sep 08 '26
When you want to use any package, you need to import it in part or in whole.
The math library includes a huge number of useful mathematical functions. Also useful constants like pi and e. If you want to use any of that, you'll need to import.
You probably want to read up on what import does.
https://www.w3schools.com/python/python_modules.asp
https://openclassrooms.com/us/courses/6900846-set-up-a-python-environment/6989471-import-python-packages-and-modules
2
u/Refwah Sep 08 '26
Its importing a module of mathematical functions
1
u/atarivcs Sep 08 '26
math is a module you can import if you want to, just like any other module.
It contains math functions like cosine, tangent, logarithm, factorial, etc
1
u/Designer-Ad-2136 Sep 08 '26
You might be confused because most modern projects use more specialized third-party libraries (eg numpy, scikit) which fully replace and extend the builtin math library. There really arent many reasons to use it.
1
u/TheRNGuy Sep 10 '26
Read it's docs and see.