Python ซับซ้อน ()ฟังก์ชัน
ตัวอย่าง
แปลงจำนวน 3 และจำนวนจินตภาพ 5 เป็นจำนวนเชิงซ้อน:
x = complex(3, 5)
ความหมายและการใช้งาน
ฟังก์ชันcomplex()
ส่งคืนจำนวนเชิงซ้อนโดยการระบุจำนวนจริงและจำนวนจินตภาพ
ไวยากรณ์
complex(real, imaginary)
ค่าพารามิเตอร์
Parameter | Description |
---|---|
real | Required. A number representing the real part of the complex number. Default 0. The real number can also be a String, like this '3+5j', when this is the case, the second parameter should be omitted. |
imaginary | Optional. A number representing the imaginary part of the complex number. Default 0. |
ตัวอย่างเพิ่มเติม
ตัวอย่าง
แปลงสตริงเป็นจำนวนเชิงซ้อน:
x = complex('3+5j')