Friday, October 24, 2025
HomeLanguagesPython – cmath.rect() method

Python – cmath.rect() method

cmath is a Python built-in module that is used for complex number mathematics. cmath module has a method rect() that is used to convert polar coordinate into rectangular form.

Syntax: cmath.rect(r, phi)

Parameter: It take two arguments. First argument r, denotes the modulus of the complex number and the second argument denotes the phase. Both arguments are required. None is optional.

Return: Returns a complex number Z whose modulus is r and phase is phi.

Note: r * (math.cos(phi) + math.sin(phi)*1j) is equivalent to this method.

Example 1: 

Python3




# Import the Library
import cmath 
  
# Printing the result
print (cmath.rect(3,10))


Output:

(-2.517214587229357-1.6320633326681093j)

Example 2: In this example modulus is taken as zero.

Python3




# Import the Library
import cmath 
  
# Printing the result
print (cmath.rect(0,1))


Output:

0j

Example 3: In this example phase is taken as zero

Python3




# Import the Library
import cmath 
  
# Printing the result
print (cmath.rect(1,0))


Output:

(1+0j)
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS