Numerics
Integer, Decimal and complex numbers
Integers
instance of int class.
exponentiation
use pow() or ** operator.
python
base = 2
power = 3
print(pow(base, power))
# 8
print(base ** power)
# 8long numbers
use _ to separate parts of number, usually thousand.
python
one_million = 1_000_000
balance = 3_974arithmetic operations
+to addition-to subtraction*to multiplication/to division%to modulo//to floor division**to exponentiation
The result of division is a float type.
python
num1 = 2
num2 = 3
# examples of each operations:
addition = num1 + num2
subtraction = num1 - num2
multiplication = num1 * num2
division = num1 / num2
modulo = num1 % num2
floor_division = num1 // num2
exponentiation = num1 ** num2Decimal numbers
instance of float class.
type conversion
It is possible to convert types
- to string using str(),
- to integer using int(),
- to float using float(),
- to boolean using bool().
rounding numbers
using round() built-in function. It rounds number to nearest integer. The type of the returned value is int.
If we convert a float to integer, we get the integer part of the number. In case of round(), nearest integer is returned.
complex numbers
an instance of complex class. It consistes of Real and Imaginary part. Use in data science or mathmatical operations. We can do arithmatic operations with complex numbers.
python
complex_1 = 4 + 2j
complex_2 = 1 + 3j
sum = complex_1 + complex_2
print(sum)
# (5+5j)
print(type(sum))
# <class 'complex'>