YouTip LogoYouTip

Python Func Complex

# Python2.x Python complex() Function [![Image 3: Python Built-in Functions](#) Python Built-in Functions](#) * * * ## Description The **complex()** function is used to create a complex number with the value `real + imag * j` or to convert a string or number to a complex number. If the first parameter is a string, the second parameter does not need to be specified. ## Syntax complex syntax: class complex([real[, imag]]) Parameter description: * real -- int, long, float, or string; * imag -- int, long, float; ## Return Value Returns a complex number. ## Example The following examples demonstrate the use of complex: >>>complex(1, 2)(1 + 2j)>>>complex(1)# Number(1 + 0j)>>>complex("1")# Treated as a string(1 + 0j)# Note: There must be no spaces around the "+" sign here, so it cannot be written as "1 + 2j", it should be "1+2j", otherwise an error will occur>>>complex("1+2j")(1 + 2j) [![Image 4: Python Built-in Functions](#) Python Built-in Functions](#)
← Python Func NextPython Func Xrange β†’