Python functions-complex () complex ([real [, imag])
Chinese description:
Create a plural value of real + imag * j or convert a string or number to a plural value. If the first parameter is a string, you do not need to specify the second parameter.
Parameter real: int, long, float or string;
Parameter imag: int, long, float.
English description:
Create a complex number with the value real + imag * j or convert a string or number to a complex number. if the first parameter is a string, it will be interpreted as a complex number and the function must be called without a second parameter. the second parameter can never be a string. each argument may be any numeric type (including complex ). if imag is omitted, it defaults to zero and the function serves as a numeric conversion function like int (), long () and float (). if both arguments are omitted, returns 0j.
Note When converting from a string, the string must not contain whitespace around the central + or-operator. for example, complex ('1 + 2j') is fine, but complex ('1 + 2j') raises ValueError.
The complex type is described in Numeric Types-int, float, long, complex.
Code example:
>>> Complex (1, 2) (1 + 2j) # number >>>> complex (1) (1 + 0j) # processing as a string >>> complex ("1") (1 + 0j) # Note: there cannot be spaces on either side of the "+, that is, it cannot be written as "1 + 2j". it should be "1 + 2j". Otherwise, an error will be reported >>> complex ("1 + 2j") (1 + 2j)