Python Numbers

Python contains both numeric and non-numeric values. It can handle long integer, floating point numbers, octal & hex numbers. Python has same precision as in C language, usually 32-bit binary number.

Integers

Integers can be both positive and negetive whole numbers and of any length. Any number without decimal point is considered as an integer.

Integer in Python is represented as Int type.

Example of Python Integers
``````>>> a = 10
>>> b = -15
>>> c = 50
>>> print(a)
10
>>> print(b)
-15
>>> print(c)
50
``````

The much larger integer is represented by long type. The long integer ends with letter L.

``````>>> 3 ** 60
42391158275216203514294433201L``````

Floats

Floats are real number with decimal point and can be both positive and negative.

Float point number is represented as float.

Example of Python Floats
``````>>> a = 10.01
>>> b = -15.100
>>> c = 50.3232
>>> print(a)
10.01
>>> print(b)
-15.1
>>> print(c)
50.3232
``````

Number Operations

These are the some examples of number operations -

``````>>> 101 + 3
104
>>> 2 - 402
-400
>>> 2 + 40 * 44
1762
>>> (39 + 2)*5
205
>>> 302 / 4
75``````

The exponential is expressed using a ** b. It means a to the b power.

``````>>> 2 ** 6
64
>>> 4.3 ** 2.0
18.49``````

Python also deal with binary, octal and hexadecimal number systems.

Example of Binary, octal & hexadecimal
``````>>> a = 0b11001
>>> b = 0144
>>> c = 0x64
>>> print(a)
25
>>> print(b)
100
>>> print(c)
100
``````

Complex Number

Complex numbers are written as, x + yj, where x and b are integers or floats and j is the imaginary number.

Example of Complex Number
``````>>> b = 10
>>> a = b + 2j
>>> c = 15
>>> print(a + c)
(25+2j)
``````

(25+2j) is the output of the above code.