Funkce Python complex() .
Příklad
Převeďte číslo 3 a imaginární číslo 5 na komplexní číslo:
x = complex(3, 5)
Definice a použití
Funkce complex()
vrací komplexní číslo zadáním reálného čísla a imaginárního čísla.
Syntax
complex(real, imaginary)
Hodnoty parametrů
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. |
Další příklady
Příklad
Převeďte řetězec na komplexní číslo:
x = complex('3+5j')