python函数示例
Python complex()函数 (Python complex() function)
complex() function is a library function in Python, it is used to get the complex number from given a real number or/and an imaginary number (which is an optional part), it accepts either a real number only or read and an imaginary number and returns a complex number.
complex()函数是Python中的一个库函数,用于从给定的实数或/和虚数(这是可选部分)中获取复数,它仅接受实数,也可以接受读数和虚数数字并返回一个复数。
Syntax:
句法:
complex(real [,Imaginary])
Parameter(s):
参数:
real – value of a real number
实数 –实数的值
Imaginary – an optional parameter, it's default value is 0.
虚构 –可选参数,默认值为0。
Return value: complex – it returns a complex type of number containing the value in the form of (real + imaginary*j).
返回值: complex –返回复杂的数字类型,其中包含(real +虚数* j)形式的值。
Example:
例:
Input:
real = 10
img = 20
print(complex(real))
print(complex(real, img))
Output:
(10+0j)
(10+20j)
Python code to get the complex number
Python代码获取复数
# python code to demonstrate example
# of complex() function
real = 10
img = 20
# complex number by passing real number
print(complex(real))
# complex number by passing real & img. number
print(complex(real, img))
# complex number by passing real part as 0
print(complex(0))
# complex number by passing real and img. part as 0, 0
print(complex(0,0))
# with float values
real = 10.23
img = 20.45
# complex number by passing real number
print(complex(real))
# complex number by passing real & img. number
print(complex(real, img))
Output
输出量
(10+0j)
(10+20j)
0j
0j
(10.23+0j)
(10.23+20.45j)
翻译自: https://www.includehelp.com/python/complex-function-with-example.aspx
python函数示例