- Author

- Name
- Nelson Silva
- Social
Introduction
In programming, we often encounter scenarios where mathematical operations are needed. Fortunately, Python offers a vast library called math, which makes such operations easier. This article aims to introduce you to some of these functions.
Main Math Functions in Python
Python offers a variety of mathematical functions. Let's take a look at some of the most common ones:
Trigonometric Functions
sin(variable): Returns the sine of the number.cos(variable): Returns the cosine of the number.tan(variable): Returns the tangent of the number.
Rounding Functions
floor(variable): Rounds down, removing the decimal part.ceil(variable): Rounds up.
Other Useful Functions
abs(variable): Provides the absolute value of the number.fsum(variable): Sums all the numbers in a list.pow(variableA, variableB): Raises the number to the given power.
from math import *
numbers = [10, 20, 30, 40, 50]
print('Result of the sin() function:', sin(10.5))
print('Result of the cos() function:', cos(10.5))
print('Result of the tan() function:', tan(10.5))
print('Result of the floor() function:', floor(10.5))
print('Result of the ceil() function:', ceil(10.5))
print('Result of the abs() function:', abs(-10.5))
print('Result of the fsum() function:', fsum(numbers))
print('Result of the pow() function:', pow(2, 5))
Exploring Other Functions of the Math Library
In addition to the functions mentioned, the math library in Python offers many other useful functions, such as logarithmic calculations, hyperbolic functions, mathematical constants, and much more. I recommend exploring the official documentation for a deeper understanding.
Conclusion
Mathematical functions in Python, especially through the math library, provide an effective way to perform complex calculations in a simple and straightforward manner. By familiarizing yourself with these functions, you will make your code more efficient and accurate in math-related tasks.