Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python complex() Function

Python complex() Function

Python built-in function Python built-in function


Description

complex() The function is used to create a complex number with the value real + imag * j, or to convert a string or number into 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:

Return Value

Returns a complex number.

Example

The following examples show the use of complex:

complex

(

1

,

2

)

(

1

2j

)

complex

(

1

)

Digit

(

1

0j

)

complex

(

"

1

"

)

Treat as a string

(

1

0j

)

Note: there must be no spaces on either side of the "+" sign here; that is, you cannot write "1 + 2j" - it should be "1+2j", otherwise an error will be reported

complex

(

"

1+2j

"

)

(

1

2j

)

Python built-in function Python built-in function