Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

วิธีสร้าง Complex Number ใน Python

Complex number ประกอบด้วย Real part และ Imaginary part Real part เป็น Float number และ Imaginary part เป็น Float number ใดๆ คูณด้วยรากที่สองของ -1 ซึ่งกำหนดเป็น j

>> no = 5 + 6j
>>> no.real
5.0
>>> no.imag
6.0
>>> type(no)

ออบเจ็กต์ที่ได้เป็น Complex data type ไลบรารี Python ยังมีฟังก์ชัน complex() ซึ่งสร้างออบเจ็กต์จากสอง Float arguments

>> no = complex(5, 6)
>>> no
(5+6j)
>>> no.real
5.0
>>> no.imag
6.0
>>> type(no)