Python complex() 函数
complex() 函数是 Python 中的一个库函数,用于从给定的实数或/和虚数(这是可选部分)中获取复数,它只接受实数或读取和虚数和返回一个复数。
用法:
complex(real [,Imaginary])
参数:
real
– 实数的值Imaginary
– 可选参数,默认值为 0。
返回值: complex
– 它返回一个复杂类型的数字,其中包含以下形式的值(real + imaginary*j)
。
例:
Input: real = 10 img = 20 print(complex(real)) print(complex(real, img)) Output: (10+0j) (10+20j)
获取复数的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))
输出
(10+0j) (10+20j) 0j 0j (10.23+0j) (10.23+20.45j)
相关用法
- Python compile()用法及代码示例
- Python PIL composite()用法及代码示例
- Python codecs.encode()用法及代码示例
- Python string count()用法及代码示例
- Python code.compile_command()用法及代码示例
- Python Wand color_matrix()用法及代码示例
- Python math copysign()用法及代码示例
- Python codeop.compile_command用法及代码示例
- Python PIL copy()用法及代码示例
- Python codecs.decode()用法及代码示例
- Python calendar firstweekday()用法及代码示例
- Python cmath.isclose()用法及代码示例
- Python cmp()用法及代码示例
- Python calendar weekday()用法及代码示例
- Python callable()用法及代码示例
- Python cmath.log10()用法及代码示例
- Python cmath.asinh()用法及代码示例
- Python OpenCV cv2.rectangle()用法及代码示例
- Python Wand charcoal()用法及代码示例
- Python calendar isleap()用法及代码示例
注:本文由纯净天空筛选整理自 complex() function with example in Python。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。