Python – cmath.polar()函数
cMath 模块包含许多用于复数数学运算的函数。 cmath.polar()函数用于将复数转换为极坐标。此函数中传递的值可以是int、float和复数。
Syntax: cmath.polar(x)
Parameter:This method accepts the following parameters.
- x :This parameter is the number to find polar coordinates of.
Returns:This method returns a tuple value that represent the polar coordinates.
下面的例子说明了上述函数的使用:
示例 #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)
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)
输出:
(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)