0% found this document useful (0 votes)
11 views

Python 2

Complex numbers in Python can be created using direct assignment or the complex() function. They consist of a real and imaginary part and support basic mathematical operations like addition, subtraction, multiplication, and division. Common attributes of a complex number include the real and imaginary parts, and its conjugate can be obtained through the conjugate() function.

Uploaded by

Andrew Rupam
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Python 2

Complex numbers in Python can be created using direct assignment or the complex() function. They consist of a real and imaginary part and support basic mathematical operations like addition, subtraction, multiplication, and division. Common attributes of a complex number include the real and imaginary parts, and its conjugate can be obtained through the conjugate() function.

Uploaded by

Andrew Rupam
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Complex Numbers in Python

A complex number is created from real numbers. Python complex number can be
created either using direct assignment statement or by using complex () function.
Complex numbers which are mostly used where we are using two real numbers. For
instance, an electric circuit which is defined by voltage(V) and current(C) are used in
geometry, scientific calculations and calculus.

Syntax
complex([real[, imag]])
Creating a simple complex number in python
>>> c = 3 +6j
>>> print(type(c))
<class 'complex'>
>>> print(c)
(3+6j)
>>>
>>> c1 = complex(3,6)
>>> print(type(c1))
<class 'complex'>
>>> print(c1)
(3+6j)

From above results, we can see python complex numbers are of type complex. Each
complex number consist of one real part and one imaginary part.
Python Complex Numbers- Attributes and Functions

>>> #Complex Number:

>>> c = (3 + 6j)

>>>

>>> #Real Part of complex number

>>> print('Complex Number: Real Part is = ', c. real)

Complex Number: Real Part is = 3.0

>>>

>>> #Imaginary Part of complex number

>>> print('Complex Number: Imaginary Part is = ', c. imag)

Complex Number: Imaginary Part is = 6.0

>>>
>>> #Conjugate of complex number

>>> print('Complex Number: conjugate Part = ', c. conjugate())

Complex Number: conjugate Part = (3-6j)

Mathematical Calculations on Complex numbers


We can do simple mathematical calculations on complex numbers:

>>> #first complex number

>>> c1 = 3 + 6j

>>> #Second complex number

>>> c2 = 6 + 15j

>>>

>>> #Addition

>>> print("Addition of two complex number =", c1 + c2)

Addition of two complex number = (9+21j)

>>>

>>> #Subtraction

>>> print("Subtraction of two complex number =", c1 - c2)

Subtraction of two complex number = (-3-9j)

>>>

>>> #Multiplication

>>> print("Multiplication of two complex number =", c1 * c2)

Multiplication of two complex number = (-72+81j)

>>>

>>> #Division

>>> print("Division of two complex number =", c1 / c2)

Division of two complex number = (0.4137931034482759-


0.03448275862068964j)

You might also like