complex

Full name
complex
Library
Built-in
Syntax

class complex([real[, imag]])

Description

The complex function returns an imaginary number from the values given as arguments for the real and imaginary part of it, or from a text string containing the representation of a complex number.

Either argument can be of any numeric type, including complex numbers (see example below). If the second argument is omitted, a value of 0 is assumed. If the two arguments are omitted, both values are assumed to be. The first argument cannot be omitted if the second argument is to be added.

Parameters
  • real: real part of the complex number to represent or text string containing the representation of a complex number.
  • imag: (optional) imaginary part of the complex number to represent. It cannot be a text string.
Examples

Examples are shown below in which the two arguments are added (both being integers), adding only real part or only imaginary part (and indicating the value 0 for the real part):

Complex function. Example of use

 

If some of the arguments is a complex number, the function adds the real and imaginary parts:

Complex function. Example of use

 

The first argument can be a text string representing a complex number. In this case, this argument cannot contain spaces around the + or - sign that joins the real and imaginary parts, and the function cannot include the second argument:

Complex function. Example of use

 

If both arguments are omitted, the complex number 0 + 0j is returned:

Complex function. Example of use

 

Submitted by admin on Sun, 01/20/2019 - 11:10