real() complex function in python by R4R Team

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

Syntax-

complex.real

Example-

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

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


program-

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

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

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

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


output-

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


-In this program, firstly we create a complex number by using complex(num,num) then we print the real part of complex number by real() 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!