Get the number of permutations in Python: Calculate nPk (the number of ways to choose and order items)
The `perm()` in `math` module returns the number of patterns to choose k objects from n objects and order them, that is nPk
Get the quotient and remainder of a division in Python
The `divmod()`, a Python built-in function, returns the quotient and remainder of a division. python a = divmod(17, 3) print(a) # (5, 2...
Python math
Zero division in Python
1 can't be devided by 0 in Python. python a = 1 / 0 # ZeroDivisionError: division by zero
Python GCD - How to get GCD of 2 integers or a list
The simplest way to get GCD of 2 integers is importing `math` module and using `gcd` function. python import math g = math.gcd(6, 8) ...
Python complex number - "j" or "J" is the imaginary unit in Python
Python complex number is expressed with `j`, which is the imaginary unit or unit imaginary number. python a = 5 + 12j b = complex(5, 12) ...
Python Hexadecimal - How to convert an integer to the hexadecimal string
Python `hex` converts an integer to the hex string. For example, 19 is 16 + 3 so 19 is converted to `0x13`. `0x` is a prefix meaning the value i...
Python max and min: How to get the max of a list, tuple, set
The `max` or `min` calculates the max or min, respectively, of a list, tuple, set, etc. python s = [1, 2, 3] a = max(s) b = min(s) p...
The average or mean of a Python list, tuple, set
The average or mean of a Python list is calculated by statistics module. python import statistics a = [1, 2, 3] m = statistics.mean(a...
Absolute value in Python: abs can calculate absolute of complex numbers
Python built-in function `abs` returns the absolute value. python print(abs(2)) # 2 print(abs(3.1)) # 3.1 print(abs(-1)) # 1 print(ab...
Python pow and math.pow: how to calculate exponentiation
In Python, double asterisks means power operator. python a = 3 ** 2 b = 3 ** 3 c = 3 ** 4 print(a) # 9 print(b) # 27 print(c) # 8...
Python division operator - And what does double slash work in Python?
In Python, slash operator works division. python x = 6 / 2 print(x) # 3.0 print(type(x)) # x is not 3 but 3.0 (...
Python String
Python List
Python Tuple
Python Set
Python Dictionary
Python Float
Python Decimal
Python Fraction
Python Date & Time
Python Function
Python Class
Python File
Python Built in
Python Math
Python Counter
Python Functools
Python Itertools
Python Deque
Python Tips
© Rollpie