I got a assignment to print complex numbers in python. First of all what complex numbers? And how to do programming in python to print complex numbers with example program and output too.

I am very basic learner in python. so would you please consider my request to explain this complex number problems in detail for me. Thanks in advance ðŸ˜€ðŸ˜€ðŸ˜€.

## Vaishnavi262

This answer was edited.To print complex numbers in python language, the logic is pretty simple and I’m writing a example program to print complex numbers in python below. First of all we see what is complex number

So, A complex number is a number which is in the form of :-

x+iy

Where x and y are real numbers

Python is a interpreted high level general purpose programming language with dynamic semantics.

So, In python we can convert two real numbers into a complex number using the complex function

z=complex (x,y);

to use this function we have to import cmath library, to access the real value of a complex number we can write z.real

And to access it’s imaginary part we can write z.img

#x + iy

import cmath

#Initializing real numbers

x = 3

y = 5

# converting x and y into complex number z = complex(x,y);

print(z)

#printing real and imaginary part of complex number

print (“The real part of complex number is : “)

print (z.real)

print (“The imaginary part of complex number is : “)

print(z.imag)

Let’s run this code

Output:-

(3+5j)

The real part of complex number is : 3.0

The imaginary part of complex number is : 5.0

## Vaishnavi262

First of all we see what is complex number

So, A complex number is a number which is in the form of :-

x+iy

Where x and y are real numbers

Python is a interpreted high level general purpose programming language with dynamic semantics.

So, In python we can convert two real numbers into a complex number using the complex function

z=complex (x,y);

to use this function we have to import cmath library, to access the real value of a complex number we can write z.real

And to access itâ€™s imaginary part we can write z.img

#x + iy

import cmath

#Initializing real numbers

x = 3

y = 5

# converting x and y into complex number z = complex(x,y);

print(z)

#printing real and imaginary part of complex number

print (â€œThe real part of complex number is : â€œ)

print (z.real)

print (â€œThe imaginary part of complex number is : â€œ)

print(z.imag)

Letâ€™s run this code

Output:-

(3+5j)

The real part of complex number is : 3.0

The imaginary part of complex number is : 5.0