imag() complex function in python by R4R Team

- imag() is a python complex function which are used to get a imaginary part of the complex number.
- complex number is made up of real and imaginary part.

Syntax-

complex.imag

Example-

complex number is n=1+2j
then n.imag will return 2

complex number is n=3+2j
then n.imag will return 2


program-

n=complex(3,2)
print("Complex number is ",n)
print("imaginary part is ",n.imag)

n=complex(1,3)
print("Complex number is ",n)
print("imaginary part is ",n.imag)

n=complex(0,1)
print("Complex number is ",n)
print("imaginary part is ",n.imag)

n=complex(-1,0)
print("Complex number is ",n)
print("imaginary part is ",n.imag)


output-

Complex number is (3+2j)
imaginary part is 2.0
Complex number is (1+3j)
imaginary part is 3.0
Complex number is 1j
imaginary part is 1.0
Complex number is (-1+0j)
imaginary part is 0.0


-In this program, firstly we create a complex number by using complex(num,num) then we print the imaginary part of complex number by imag() function.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!