Complex ([real[, Imag]])
English Description:
Create a complex number with a value of real + imag * J or convert a string or count to plural. If the first argument is a string, you do not need to specify a second argument.
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'll be interpreted as a complex number and the function must be called without a s Econd parameter. The second parameter can never be a string. Each argument is 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 FL Oat (). If Both arguments is 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 ') was 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) #数字 >>> Complex (1) (1 + 0j) #当做字符串处理 >>> Complex ("1") (1 + 0j) #注意: This place is in the "+ "No space on either side, that is, can not be written as" 1 + 2j ", should be" 1+2j ", otherwise will error >>> complex (" 1+2j ") (1 + 2j)