ScanSkill

complex data type

complex data type represents the extension of a real number system in which all numbers are expressed as a sum of a real part and an imaginary part. Imaginary numbers are real multiples of the imaginary unit(whose value is a square root of -1).

Python supports complex numbers, which are written with this latter notation; the imaginary part is written with a j suffix, e.g., 3+1j.

And the complex numbers are stored as a pair of machine-level double-precision floating point numbers.

Constructors

  • complex(): It converts an expression into a complex number.
  • literal syntax: It is used to initialize a new instance of the complex data type. e.g.

Complex numbers can be simply initialized as a sum of real and imaginary parts:

>>> 1+2j
(1+2j)
>>> 1.0+2.0j
(1+2j)

Properties

  • real: This is used to retrieve the real component of the complex number.

Syntax:

complex.real

Example:

>>> (1+3j).real
1.0
  • imag: This is used to retrieve the imaginary part of the complex number.

Syntax:

complex.imag

Example:

>>> (1+3j).imag
3.0

Method

  • conjugate: This returns the complex conjugate.

Syntax:

complex.conjugate()

Example:

>>> (1+3j).conjugate()
(1-3j)