So what about precision and accuracy that we need to know of. Well, following example will illustrate it.

Wait, what just happened?

Turns out a floating point number in Python is accurate up to 15 decimal places and the 16th digit after the decimal point is left out because of its insignificance considered by Python, whereas in actual the output must have been 0.0000000000000001 in the second example as well.

So, in Python we must be aware of some probable marginal errors.

Python complex numbers

A complex number is a number expressed in the form a+bj, where a and b are real numbers ( a is called real part and b is called imaginary part) and j is the imaginary part.

For example 2+3j, 1+4j, 2-5j etc.

Let’s learn about how to declare complex numbers in python and extract their real and imaginary parts.

>>> a = complex(1,2)
1 + 2j
>>> a.real
1.0
>>> a.imag
2.0

As seen in above example, complex() function is used to generate complex numbers.

Note: j is not case-sensitive, meaning you can use 'j' as well as 'J'. But you cannot use 'j' without including b. If you use j alone without b, Python interpreter will treat j as a variable and throw an error.