當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python cmath.polar()用法及代碼示例

cMath模塊包含許多函數,這些函數用於對複數進行數學運算。 cmath.polar()函數用於將複數轉換為極坐標。在此函數中傳遞的值可以是int,float和複數。

用法: 
cmath.polar(x)

參數:此方法接受以下參數。

  • x:此參數是查找極坐標的數字。

返回值:這個方法返回表示極坐標的元組值。

以下示例說明了上述函數的用法:

範例1:



Python3

# Python code to implement 
# the polar()function 
        
# importing "cmath" 
# for mathematical operations   
import cmath  
    
# using cmath.polar() method  
val = cmath.polar(1)  
print(val)

輸出:

(1.0, 0.0)

範例2:

Python3

# Python code to implement 
# the polar()function 
        
# importing "cmath" 
# for mathematical operations   
import cmath  
    
# using cmath.polar() method  
val = cmath.polar(2 + 4j) 
print(val)

輸出:

(4.47213595499958, 1.1071487177940904)

相關用法


注:本文由純淨天空篩選整理自SHUBHAMSINGH10大神的英文原創作品 Python – cmath.polar() function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。