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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。