Skip to main content

Python cmath Module

 

Python cmath Module


Python cmath Module

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

The methods in this module accepts intfloat, and complex numbers. It even accepts Python objects that has a __complex__() or __float__() method.

The methods in this module almost always return a complex number. If the return value can be expressed as a real number, the return value has an imaginary part of 0.

The cmath module has a set of methods and constants.


cMath Methods

MethodDescription
cmath.acos(x)Returns the arc cosine value of x
cmath.acosh(x)Returns the hyperbolic arc cosine of x
cmath.asin(x)Returns the arc sine of x
cmath.asinh(x)Returns the hyperbolic arc sine of x
cmath.atan(x)Returns the arc tangent value of x
cmath.atanh(x)Returns the hyperbolic arctangent value of x
cmath.cos(x)Returns the cosine of x
cmath.cosh(x)Returns the hyperbolic cosine of x
cmath.exp(x)Returns the value of Ex, where E is Euler's number (approximately 2.718281...), and x is the number passed to it
cmath.isclose()Checks whether two values are close, or not
cmath.isfinite(x)Checks whether x is a finite number
cmath.isinf(x)Check whether x is a positive or negative infinty
cmath.isnan(x)Checks whether x is NaN (not a number)
cmath.log(x[, base])Returns the logarithm of x to the base
cmath.log10(x)Returns the base-10 logarithm of x
cmath.phase()Return the phase of a complex number
cmath.polar()Convert a complex number to polar coordinates
cmath.rect()Convert polar coordinates to rectangular form
cmath.sin(x)Returns the sine of x
cmath.sinh(x)Returns the hyperbolic sine of x
cmath.sqrt(x)Returns the square root of x
cmath.tan(x)Returns the tangent of x
cmath.tanh(x)Returns the hyperbolic tangent of x

cMath Constants

ConstantDescription
cmath.eReturns Euler's number (2.7182...)
cmath.infReturns a floating-point positive infinity value
cmath.infjReturns a complex infinity value
cmath.nanReturns floating-point NaN (Not a Number) value
cmath.nanjReturns coplext NaN (Not a Number) value
cmath.piReturns PI (3.1415...)
cmath.tauReturns tau (6.2831...)

Comments

Popular posts from this blog

Python Lists

  Python  Lists mylist = [ "apple" ,  "banana" ,  "cherry" ] List Lists are used to store multiple items in a single variable. Lists are one of 4 built-in data types in Python used to store collections of data, the other 3 are  Tuple ,  Set , and  Dictionary , all with different qualities and usage. Lists are created using square brackets: Example Create a List: thislist = [ "apple" ,  "banana" ,  "cherry" ] print (thislist) List Items List items are ordered, changeable, and allow duplicate values. List items are indexed, the first item has index  [0] , the second item has index  [1]  etc. Ordered When we say that lists are ordered, it means that the items have a defined order, and that order will not change. If you add new items to a list, the new items will be placed at the end of the list. Changeable The list is changeable, meaning that we can change, add, and remove items in a list after it has been created. Allow Duplicat...

Python Tuples

  Python  Tuples mytuple = ( "apple" ,  "banana" ,  "cherry" ) Tuple Tuples are used to store multiple items in a single variable. Tuple is one of 4 built-in data types in Python used to store collections of data, the other 3 are List, Set, and Dictionary, all with different qualities and usage. A tuple is a collection which is ordered and  unchangeable . Tuples are written with round brackets. Example Create a Tuple: thistuple = ( "apple" ,  "banana" ,  "cherry" ) print (thistuple) Tuple Items Tuple items are ordered, unchangeable, and allow duplicate values. Tuple items are indexed, the first item has index  [0] , the second item has index  [1]  etc. Ordered When we say that tuples are ordered, it means that the items have a defined order, and that order will not change. Unchangeable Tuples are unchangeable, meaning that we cannot change, add or remove items after the tuple has been created. Allow Duplicates Since tuples...

Python Variables

  Python  Variables Variables Variables are containers for storing data values. Creating Variables Python has no command for declaring a variable. A variable is created the moment you first assign a value to it. Example x =  5 y =  "John" print (x) print (y) Variables do not need to be declared with any particular  type , and can even change type after they have been set. Example x =  4         # x is of type int x =  "Sally"   # x is now of type str print (x) Casting If you want to specify the data type of a variable, this can be done with casting. Example x =  str ( 3 )     # x will be '3' y =  int ( 3 )     # y will be 3 z =  float ( 3 )   # z will be 3.0 Get the Type You can get the data type of a variable with the  type()  function. Example x =  5 y =  "John" print ( type (x)) print ( type (y)) Single or Double Quotes? Strin...