Home >Backend Development >Python Tutorial >What does complex mean in python?
complex() function is used to create a complex number with a value of real imag * j or to convert a string or number into a complex number. If the first parameter is a string, there is no need to specify the second parameter. (Recommended: Python Programming Video)
Grammar
complex Grammar:
class complex([real[, imag]])
Parameter description:
real -- int, long, float or string;
imag -- int, long, float;
Return value
Returns a complex number.
Examples
The following examples demonstrate the use of complex:
>>>complex(1, 2) (1 + 2j) >>> complex(1) # 数字 (1 + 0j) >>> complex("1") # 当做字符串处理 (1 + 0j) # 注意:这个地方在"+"号两边不能有空格,也就是不能写成"1 + 2j",应该是"1+2j",否则会报错 >>> complex("1+2j") (1 + 2j)
The above is the detailed content of What does complex mean in python?. For more information, please follow other related articles on the PHP Chinese website!