x = 1
y = 35656225487711
z = -825552
print(type(x), type(y), type(z))<class 'int'> <class 'int'> <class 'int'>
Link to the Google Colaboratory notebook: 3-Numbers
There are three different types of native numbers: int, float and complex.
An integer int is a positive or negative number without decimals.
A float is positive or negative number containing one or more decimals.
It can also be a scientific number, specified by the e that indicates a power of 10.
A complex number is written with the j as the imaginary part.
Python arithmetic operators are used to perform mathematical operations on numerical values.
| Operator | Name | Example |
|---|---|---|
| + | Addition | 10 + 20 = 30 |
| - | Subtraction | 20 – 10 = 10 |
| * | Multiplication | 10 * 20 = 200 |
| / | Division | 20 / 10 = 2 |
| % | Modulus | 22 % 10 = 2 |
| ** | Exponent | 4**2 = 16 |
| // | Floor Division | 9//2 = 4 |
x, y = 100, 5
print("Addition", x+y)
print("Subtraction", x-y)
print("Multiplication", x*y)
print("Division", x/y)
print("Modulus", x%y)
print("Exponent", x**y)
print("Floor division", x//y)Addition 105
Subtraction 95
Multiplication 500
Division 20.0
Modulus 0
Exponent 10000000000
Floor division 20
Python assignment operators are used to assign values to variables.
| Operator | Name | Example |
|---|---|---|
| = | Assignment Operator | a = 10 |
| += | Addition Assignment | a += 5 (Same as a = a + 5) |
| -= | Subtraction Assignment | a -= 5 (Same as a = a - 5) |
| *= | Multiplication Assignment | a *= 5 (Same as a = a * 5) |
| /= | Division Assignment | a /= 5 (Same as a = a / 5) |
| %= | Remainder Assignment | a %= 5 (Same as a = a % 5) |
| **= | Exponent Assignment | a **= 2 (Same as a = a ** 2) |
| //= | Floor Division Assignment | a //= 3 (Same as a = a // 3) |
# Assignment Operator
a = 10
# Addition Assignment
a += 5
print ("a += 5 : ", a)
# Subtraction Assignment
a -= 5
print ("a -= 5 : ", a)
# Multiplication Assignment
a *= 5
print ("a *= 5 : ", a)
# Division Assignment
a /= 5
print ("a /= 5 : ",a)
# Remainder Assignment
a %= 3
print ("a %= 3 : ", a)
# Exponent Assignment
a **= 2
print ("a **= 2 : ", a)
# Floor Division Assignment
a //= 3
print ("a //= 3 : ", a)a += 5 : 15
a -= 5 : 10
a *= 5 : 50
a /= 5 : 10.0
a %= 3 : 1.0
a **= 2 : 1.0
a //= 3 : 0.0