How to do math in Python

1 min

Python provides various built-in mathematical operations and functions that can be used to perform mathematical calculations.

Here are some examples of basic mathematical operations in Python:

result = 3 + 4

result = 5 - 2

result = 3 * 4

result = 8 / 2

result = 2 ** 3

You can also use the math module to perform more advanced mathematical operations such as trigonometric functions, logarithms and more.

import math

#square root
result = math.sqrt(16)

result = math.sin(math.pi/2)

result = math.log10(100)

You can also use the NumPy library which provides advanced mathematical functions such as linear algebra, Fourier transform, and more.

In addition to that, python also has some libraries specific for scientific computations like scipy and pandas which will allow you to perform a wide range of mathematical and scientific computations.