This function can create a complex number by using the argument real + Imag*j method. You can also convert a string number to a plural, or convert a number to a plural. If the first argument is a string and the second argument is not filled in, the string is interpreted and the plural is returned; however, the second argument cannot be entered as a string, otherwise an error occurs. Real and Imag parameters can enter numbers, and if the Imag parameter is not entered, the default is 0 value, which is equivalent to the function of int () or float (). If both real and Imag parameters are entered in 0, this function returns 0J. With this function, you can easily convert a list to a plural form.
Note: When you want to convert a complex number from a plural of a string, it is necessary to note that no spaces can appear in the middle of the string, such as writing complex (' 1+2j '), rather than writing complex (1 +2j '), or return a ValueError exception.
Example:
Copy Code code as follows:
#complex ()
Print (complex (1))
Print (Complex (' 2+1j '))
Print (Complex (2, 5))
L = [1, 3, 4, 5]
For I in L:
Print (Complex (I, 5))
The resulting output is as follows:
Copy Code code as follows:
(1+0J)
(2+1j)
(2+5j)
(1+5j)
(3+5j)
(4+5j)
(5+5j)