complex()

complex('real','imaginary') returns complex number
real: Required, ( default 0 ) the real part of the complex number. Can be a string input
imaginary: (optional) ( default = 0 ) Imaginary part of the complex number .

We can create a complex number and check the data type by using type()
x=complex(4,3)
print(type(x)) # <class 'complex'>
print(x)       # (4+3j)

Real and Imaginary parts

We can read real and imaginary part by using real & imag methods. These methods will return float data type.
x=complex(4,3)
print(x.real)       # 4.0
print(x.imag)       # 3.0
print(type(x.imag)) # <class 'float'>
print(type(x.real)) # <class 'float'>
We can use string input as real part. In this case there is no imaginary part.
x=complex('4+3j')
print(type(x)) # <class 'complex'>
Above code will return error if imaginary part is added.
x=complex('4+3j',4)
Error
All Built in Functions in Python bin() int() float()


plus2net.com



Post your comments , suggestion , error , requirements etc here




We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2020 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer