Nums Flashcards
Num operations
Addition: 5 + 2
Subtraction: 5 - 2
Multiplication: 5 * 2
Exponentiation: 5 ** 2 ⇔ 5²
Division: 5 / 2 ⇒ 2.5
Floor Division: 5 // 2 ⇒ 2
Modulus: 5 % 2 ⇒ 1
a = 1
a+=1
a++ is not valid in python
Absolute value of a number
print(abs(-5)) # Output: 5
Adds all the elements of an iterable, like a list
print(sum([1, 2, 3])) # Output: 6
Raise a number to the power of another
pow(): Raises a number to the power of another.
pow(x, y) is equivalent to x**y. For example, pow(2, 3) would return 8.
Round a floating-point number to a specified number of decimal places
print(round(3.14159, 2)) # Output: 3.14
Return the smallest and largest values from an iterable
print(min([1, 2, 3])) # Output: 1
print(max([1, 2, 3])) # Output: 3
Calculate the square root of a number
import math
print(math.sqrt(9)) # Output: 3.0
You need to import the math module to use this function.
Calculates the factorial of a number.
import math
print(math.factorial(5)) # Output: 120
Compute logarithms in different bases