Number data types store numeric values. Number objects are created when you assign a value to them.

Python supports three different numerical types.

**int**(signed integers)**float**(floating point real values)**complex**(complex numbers)

Variables of numeric types are created when you assign a value to them.

a= 10b = 7.8c = 10j

You can verify the type of any object in Python, there is type() function that prints the type of the object.

print(type(a)) # intprint(type(b)) # floatprint(type(c)) # complex

**int (Signed Integers)**

You can use **int** data type to represent whole numbers (integral values), positive or negative, without decimals, of unlimited length.In Python 2.x, there was a long data type to represent very large integral values. Whereas in Python 3.x, there is no long type explicitly and long values are represented by using int type only.

a= 10b = 2323232323887711c = -7777372522print(type(a)) #intprint(type(b)) #intprint(type(c)) #int

You can represent int values in the following ways.

- Decimal Form
- Binary Form
- Octal Form
- Hexa decimal Form

**Decimal Form (base-10)**

It is the default number system in Python. The allowed digits are from 0 to 9.

a = 10

**Binary Form (Base-2)**

The allowed digits are 0 & 1. Literal value should be prefixed with 0b or 0B.

a = 0B1111b = 0B123c = 0b111

**Octal Form(Base-8)**

The allowed digits are 0 to 7. Literal value should be prefixed with 0o or 0O.

a=0O123b=0o456

**Hexa Decimal Form(Base-16)**

The allowed digits are : 0 to 9, a-f (both lower and upper cases are allowed). Literal value should be prefixed with 0x or 0X.

a =0XFACEa=0XAbcda =0XBeer

**Note :** Being a programmer, you can specify literal values in decimal, binary, octal and hexa decimal forms. But PVM will always print values in decimal form only.

a=10b=0o10c=0X10d=0B10#Here it will print output in decimal forms only.print(a) # 10print(b) # 8print(c) # 16print(d) # 2

**Float (floating point real values)**

You can use float data type to represent floating point values, positive or negative, containing one or more decimals.

f=1.234print(type(f)) # float

You can also represent floating point values by using exponential form (scientific notation).

f=1.2e3print(f) # 1200.0

instead of ‘**e**‘ we can use ‘**E**‘. The main advantage of exponential form is we can represent big values in less memory.

**Note:** You can represent int values in decimal, binary, octal and hexa decimal forms. But you can represent float values only by using decimal form.

**Complex (complex numbers)**

A complex number contains real and imaginary part. For instance, a+bj, here a is real part and b is imaginary part. And a and b can be integers or floating point values.

3+5j10+5.5j0.5+0.1j

In the real part if you use int value then you can specify that either by decimal,octal,binary or hexa decimal form. But imaginary part should be specified only by using decimal form.

**Random Number**

Python does not contain a random() function to make a random numbers, but Python has a built-in module called random. You can use random module to make random numbers.

import randomprint(random.randrange(1, 10))

It will print a random number between 1 and 10. It could be any number.

**Previous Read : Python Data Types**

## 1 thought on “Python Numbers”