English documents:
Class Complex ([Real[, Imag]])
Return a complex number with the "value real" + imag*1j or convert a string or number to a complex number. If the parameter is a string, it would 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 constructor serves as a numeric-like int and float. If both arguments are omitted, returns 0J.
Note
When converting from a string, the string must not contain whitespace around the "the". For example, complex (' 1+2j ') is fine, but complex (' 1 + 2j ') raises valueerror.
Description
1. function function, return a complex number. There are two optional parameters.
2. When two parameters are not provided, return the complex number 0j.
3. When the first argument is a string, the second argument cannot be supplied at the time of the call. At this point, the string argument needs to be a string that can represent a complex number, and no spaces can appear around the plus or minus signs.
>>> complex (' 1+2j ', 2) #第一个参数为字符串, cannot accept the second argument
Traceback (most recent call last):
File "<pyshell#2 > ", Line 1, in <module>
complex (' 1+2j ', 2)
Typeerror:complex () can ' t take second arg if a string
>>> Complex (' 1 + 2j ') #不能有空格
Traceback (most recent):
File "<pyshell#3>", line 1, in <module>
complex (' 1 + 2j ')
V Alueerror:complex () arg is a malformed string
4. When the first parameter is int or float, the second argument can be null, indicating that the imaginary part is 0, and if the second argument is supplied, the second argument must be int or float.
>>> Complex (2)
(2+0j)
>>> Complex (2.1,-3.4)
(2.1-3.4j)
Thank you for reading, I hope to help you, thank you for your support for this site!