Basic Math Operations
In any programming language, one of the very basic tasks is to perform various mathematical calculations. These calculations can be performed by using the arithmetic operators that we have in basic maths! Using these operators combined with some other different aspects of the programming language can produce interesting results. A list of some common mathematical operators in programming languages is given below. The examples assume that the values of a
and b
are equal to 10.
Operator | Operation | Example |
---|---|---|
+ | Addition | a + b = 20 |
- | Subtraction | a - b = 10 |
* | Multiplication | a * b = 100 |
/ | Division | a / b = 1 |
% | Modulus | a % b = 0 |
** | Exponent | a ** b = 1 x 10^10 |
Let's see these operations in action by looking at some code examples in Python.