Numbers in the Python shell

Typing a number at the Python shell prompt simply echoes the number back to you:

>>> 5
5
>>> 5.
5.0
>>> 0.10
0.1
>>> 0.0001
0.0001
>>> 0.0000999
9.99e-05

Note that the Python interpreter displays numbers in a standard way. For example, numbers smaller in magnitude than 0.0001 are displayed in scientific notation.

A number of one type can be created from a number of another type with the relevant constructor:

>>> float(5)
5.0
>>> int(5.2)
5
>>> int(5.9)
5

Note that a floating point number is rounded down in casting it into an integer.

Constructing a complex object from a float generates a complex number with the imaginary part equal to zero:

>>> complex(3.)
(3+0j)

To generate a pure imaginary number, you have to explicitly pass two numbers to complex with the first, real part, equal to zero:

>>> complex(0., 3.)
3j