Python – cmath.tan()函数
cmath是用于复数数学的Python内置模块。 cmath 模块有一个方法 tan(),它返回传递给它的复数的正切。
Syntax: cmath.tan(Z)
Parameter: It requires only one parameter i.e the number for which tangent needs to be calculated.
Return: Returns a complex number that is the tangent of the number passed.
示例 1:
Python3
# Import the Library
import cmath
# Printing the result
print (cmath.tan(5 + 3j))
Python3
# Import the Library
import cmath
# Printing the result
print (cmath.tan(1))
Python3
# Import the Library
import cmath
# Printing the result
print (cmath.tan())
输出:
(-0.002708235836224072+1.0041647106948153j)
示例 2:在此示例中传递了实数,但返回的结果仍然是复数。
Python3
# Import the Library
import cmath
# Printing the result
print (cmath.tan(1))
输出:
(1.5574077246549023+0j)
示例 3:在此示例中,在这种情况下不传递任何参数,TypeError 将被抛出
Python3
# Import the Library
import cmath
# Printing the result
print (cmath.tan())
输出:
TypeError: tan() takes exactly one argument (0 given)