import math
print(math.log(2)) # 0.6931471805599453
With different base
import math
print(math.log(2,3)) # 0.6309297535714574
print(math.log(4,5)) # 0.8613531161467861
Using negative number import math
print(math.log(-2))
print(math.log(0))
Above code will generate error.
import math
try:
output = math.log(-2)
except ValueError as e:
print(f"Error: {e}")
log(x)/log(y) is same as log(x,y). Check this code.
import math
x=2
y=4
print(math.log(x)) # 0.6931471805599453
print(math.log(y)) # 1.3862943611198906
print(math.log(x,y)) # 0.5
print(math.log(x)/math.log(y)) # 0.5
import math
x = 8
output = math.log(x, 2)
print(output) # Output: 3.0
Output:
3.0
Output:
Error: math domain error
log10
modf()
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.
05-02-2023 | |
| X,Y on the same axis overlapping; however each carries its own width and length | |