In python a number of mathematical operations can be performed with ease by importing a module named “math” which defines various functions which makes our tasks easier.
1. ceil() :- This function returns the smallest integral value greater than the number. If number is already integer, same number is returned.
2. floor() :- This function returns the greatest integral value smaller than the number. If number is already integer, same number is returned.
The ceil of 2.3 is : 3 The floor of 2.3 is : 2
3. fabs() :- This function returns the absolute value of the number.
4. factorial() :- This function returns the factorial of the number. An error message is displayed if number is not integral.
The absolute value of -10 is : 10.0 The factorial of 5 is : 120
5. copysign(a, b) :- This function returns the number with the value of ‘a’ but with the sign of ‘b’. The returned value is float type.
6. gcd() :- This function is used to compute the greatest common divisor of 2 numbers mentioned in its arguments. This function works in python 3.5 and above.
The copysigned value of -10 and 5.5 is : -5.5 The gcd of 5 and 15 is : 5
This article is contributed by Manjeet Singh .If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Mathematical Functions in Python | Set 2 (Logarithmic and Power Functions)
- Mathematical Functions in Python | Set 3 (Trigonometric and Angular Functions)
- Mathematical Functions in Python | Set 4 (Special Functions and Constants)
- Python | Mathematical Median of Cumulative Records
- Plot Mathematical Expressions in Python using Matplotlib
- Evaluate the Mathematical Expressions using Tkinter in Python
- Mathematical explanation for Linear Regression working
- ML | Mathematical explanation of RMSE and R-squared error
- Q-learning Mathematical Background
- Chi-Square Test for Feature Selection - Mathematical Explanation
- Program to print numeric pattern | Set - 2
- Python Regex to extract maximum numeric value from a string
- Sort numeric strings in a list in Python
- Python | Ways to remove numeric digits from given string
- Python | Add only numeric values present in a list
- Python | Get the numeric prefix of given string
- Python | Check if given string is numeric or not
- Python | Check Numeric Suffix in String
- Python | Get numeric prefix of given string
- Python | Convert numeric String to integers in mixed List