Professional Documents
Culture Documents
Python
1. Integer
a. A whole number with no decimal places
2. Float
a. A number with decimal places
Numbers: Arithmetic Operators
Cheat Sheet
+ Addition
Integer + Integer:
>>> 1 + 1
2
>>> 3 + 4
7
Integer + Float:
>>> 1 + 1.0
2.0
>>> 9 + 2.7
11.7
Float + Float:
>>> 1.0 + 1.0
2.0
>>> 3.0 + 4.0
7.0
- Subtraction
Integer - Integer:
>>> 8 - 2
6
>>> 53 - 12
41
Integer - Float:
>>> 3 - 2.0
1.0
>>> 9 - 8.7
0.3
Float - Float:
>>> 8.0 - 2.0
6.0
>>> 53.0 - 12.0
41.0
Numbers: Arithmetic Operators
Cheat Sheet
* Multiplication
Integer * Integer:
>>> 10 * 10
100
>>> 8 * 4
32
Integer * Float:
>>> 2 * 3.0
6.0
>>> 7 * 3.7
25.9
Float * Float:
>>> 10.0 * 10.0
100.0
>>> 8.0 * 4.0
32.0
Numbers: Arithmetic Operators
Cheat Sheet
/ Division
Integer / Integer:
>>> 20 / 10
2.0
>>> 8 / 5
1.6
Integer * Float:
>>> 9 / 3.0
3.0
>>> 8 / 2.7
2.96296296
Float / Float:
>>> 20.0 / 10.0
2.0
>>> 8.0 / 5.0
1.6
Numbers: Arithmetic Operators
Cheat Sheet
// Integer Division
Integer // Integer:
>>> 20 // 10
2
>>> 8 // 5
1
>>> -3 // 2
-2
Integer // Float:
>>> 9 // 3.0
3.0
>>> 8 // 2.7
2.0
>>> -12 // 4.0
-3.0
Float // Float:
>>> 20.0 // 10.0
2.0
>>> 8.0 // 5.0
1.0
Numbers: Arithmetic Operators
Cheat Sheet
Integer ** Integer:
>>> 2**2
4
>>> 2**3
8
Integer ** Float:
>>> 3**2.0
9.0
>>> 3**3.0
27.0
Float ** Integer:
>>> 3.0**2
9.0
>>> 3.0**3
27.0
Float ** Float:
>>> 4.0**2.0
16.0
>>> 4.0**3.0
64.0
Numbers: Arithmetic Operators
Cheat Sheet
% Modulus Operator
Integer % Integer:
>>> 5 % 2
1
>>> 7 % 3
1
>>> -5 % 2
1
Integer % Float:
>>> 11 % 3.0
2.0
>>> 3 % 3.0
0.0
>>> 11 % -2
-1
Float % Integer:
>>> 11.0 % 3
2.0
>>> 3.0 % 3
0.0
>>> -5.0 % -3.0
-2.0
Float % Float:
>>> 19.0 % 5.0
4.0
>>> 26.0**7.0
5.0
Numbers: Arithmetic Expressions
Cheat Sheet
P - Parenthesis
E - Exponents
M - Multiplication
D - Division
A - Addition
S - Subtraction
Single Argument:
>>> round(2.4)
2
>>> round(5.6)
6
Two Argument:
>>> round(5.68434,3)
5.684
>>> round(20.183649,5)
20.18365
abs() You can use abs() to find the absolute value of a number;
integer or float, positive or negative.
>>> abs(-4)
4
>>> abs(-9.84)
9.84
Numbers: Functions
Cheat Sheet
>>> pow(2,2)
4
>>> pow(5,3)
125
>>> pow(2,-2)
0.25
>>> int('56')
56
>>> int(56.8)
56
>>> float('44')
44.0
>>> float(83)
83.0