>>> a = 5
>>> # Output: <class 'int'>
>>> print(type(a))
<class 'int'>
>>> # Output: <class 'float'>
>>> print(type(6.3))
<class 'float'>
>>> # Output: (9+7j)
>>> c = 5 + 7j
>>> print(c + 7)
(12+7j)
>>> # Output: True
>>> print(isinstance(c, complex))
True
>>>
Python supports the following operators on numbers.
+
addition
-
subtraction
*
multiplication
/
division
**
exponent
%
remainder
>>> 10+15
25
>>> 10-5
5
>>> 10*7
70
>>> 10/3
3.3333333333333335
>>> 10**2
100
>>> 10%2
0
>>>
The operators have precedence, a kind of priority that determines which operator is applied first. Among the numerical operators, the precedence of operators is as follows, from low precedence to high.
+, -
*, /, %
**
When we compute 2 + 3 * 4, 3 * 4
is computed first as the precedence of * is higher than + and then the result is added to 2.
>>> 2 + 3 * 4
14
>>> (2 + 3) * 4
20