This is a draft cheat sheet. It is a work in progress and is not finished yet.
Math Operations
a = 3 |
b = 4 |
a + b |
Sum a and b (7) |
a - b |
Subtract b from a (-1) |
a * b |
a times b (12) |
a / b |
a divided by b (0.75) |
a // b |
Integer part of a divided by b (0) |
a % b |
Rest of a divided by b (3) |
a ** b |
a to the power of b (81) |
Logic Tests
5 > 3 |
Tests if 5 is greater than 3 (True) |
5 >= 3 |
Tests if 5 is greater than or equal to 3 (True) |
5 == 3 |
Tests if 5 is equal to 3 (False) |
5 != 3 |
Tests if 5 is different than 3 (True) |
5 <= 3 |
Tests if 5 is lower than or equal to 3 (False) |
5 < 3 |
Tests if 5 is lower than 3 (False) |
not True |
Opposite of True (False) |
Math Module
import math |
Imports module math |
math.ceil(x) |
Rounds x up |
math.floor(x) |
Rounds x down |
round(x) |
Rounds x with 0 decimal places |
round(x, 2) |
Rounds x with 2 decimal places |
math.sqrt(x) |
Square root of x |
math.sin(angle) |
Sine of angle |
math.cos(angle) |
Cosine of angle |
math.tan(angle) |
Tangent of angle |
math.sinh(x) |
Hiperbolic sine of x |
math.cosh(x) |
Hiperbolic cosine of x |
math.tanh(x) |
Hiperbolic tangent of x |
math.asin(angle) |
Arc sine of angle |
math.acos(angle) |
Arc cosine of angle |
math.atan(angle) |
Arc tangent of angle |
math.asinh(x) |
Inverse hiperbolic sine of x |
math.acosh(x) |
Inverse hiperbolic cosine of x |
math.atanh(x) |
Inverse hiperbolic tangent of x |
math.degrees(angle) |
Covert rad_angle from radians to degrees |
math.radians(angle) |
Covert rad_angle from degrees to radians |
math.factorial(x) |
Factorial of x |
math.gamma(x) |
Gamma function of x |
math.exp(x) |
e to the power of x |
math.log(x) |
Natural logarithm of x |
math.log(x, 2) |
Base 2 logarithm of x |
math.e |
Constant e |
math.pi |
Constant pi |
Round is not part of the math module. |
The python standard is to work with angles in radians. |
Second Degree Equation Roots
# This script solves ax^2 + bx + c = 0
import math
a = 1
b = -1
c = -6
delta = b2 - 4 ac
r1 = (-b + math.sqrt(delta))/(2*a)
r2 = (-b - math.sqrt(delta))/(2*a)
print(f"r1 = {r1}")
print(f"r2 = {r2}")
|
Triangle Angles
# Calculates the angles of a triangle based on its
sides.
import math
side1, side2, side3 = 3, 4, 5
angle1 = math.atan(side2/side1)
angle2 = math.acos(side2/side3)
print(f"angle 1 = {math.degrees(angle1)}")
print(f"angle 2 = {math.degrees(angle2)}")
|
angle 1 = 53.13010235415598
angle 2 = 36.86989764584401
|
|
Data Types
Name |
Type |
Description |
Integers |
int |
Whole numbers, such as: 3 300 200 |
Floating point |
float |
Numbers with a decimal point: 2.3 4.6 100.0 |
Strings |
str |
Ordered sequence of characters: "hello" 'Sammy' "2000" "楽しい" |
Lists |
list |
Ordered sequence of objects: [10,"hello",200.3] |
Dictionaries |
dict |
Unordered Key:Value pairs: {"mykey" : "value" , "name" : "Frankie"} |
Tuples |
tup |
Ordered immutable sequence of objects: (10,"hello",200.3) |
Sets |
set |
Unordered collection of unique objects: {"a","b"} |
Booleans |
bool |
Logical value indicating True or False |
|
|
|