Python complex() Funzione
Esempio
Converti il numero 3 e il numero immaginario 5 in un numero complesso:
x = complex(3, 5)
Definizione e utilizzo
La complex()
funzione restituisce un numero complesso specificando un numero reale e un numero immaginario.
Sintassi
complex(real, imaginary)
Valori dei parametri
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. |
Altri esempi
Esempio
Converti una stringa in un numero complesso:
x = complex('3+5j')