SwadhyAI Notes

All Python notes

Python cmath Module 🔢

cmath Module

Python has a built-in module that you can use for mathematical tasks for complex numbers.

✨ Common cmath Methods

MethodDescription
acos()Returns the arc cosine of a complex number
acosh()Returns the inverse hyperbolic cosine of a complex number
asin()Returns the arc sine of a complex number
asinh()Returns the inverse hyperbolic sine of a complex number
atan()Returns the arc tangent of a complex number
atanh()Returns the inverse hyperbolic tangent of a complex number
cos()Returns the cosine of a complex number
cosh()Returns the hyperbolic cosine of a complex number
exp()Returns E raised to the power of x
isclose()Checks whether two values are close to each other, or not
isfinite()Checks whether a number is finite or not
isinf()Checks whether a number is infinite or not
isnan()Checks whether a value is NaN (not a number) or not
log()Returns the natural logarithm of a number, or the logarithm of number to base
log10()Returns the base-10 logarithm of x
phase()Return the phase of a complex number
polar()Convert a complex number to polar coordinates
rect()Convert polar coordinates to rectangular form
sin()Returns the sine of a complex number
sinh()Returns the hyperbolic sine of a complex number
sqrt()Returns the square root of a complex number
tan()Returns the tangent of a complex number
tanh()Returns the hyperbolic tangent of a complex number

💡 Did You Know?

The cmath module also defines constants like cmath.pi, cmath.e, cmath.tau, cmath.inf, cmath.infj, cmath.nan, and cmath.nanj.