Python Numeric Types


The Numeric Types in Python are the integer datatypes. It includes integers, floatimg point, complex, etc. The complex includes real and imag parts. Also, includes Hexadecimal and Octal types.

Python int datatype

The Numeric Types include the int datatypes −

a = 5 print("Integer = ",a) print("Type = ",type(a))

Output

Integer = 5
Type = <class 'int'>

Python float datatype

The Numeric Types include the float datatypes −

Example

a = 7E2 print("Float = ",a) print("Type = ",type(a))

Output

Float = 700.0
Type = <class 'float'>

Python complex datatype

The Numeric Types include the complex datatypes with real and imaginary values −

Example

a = 2.75+3.15j print("Complex = ",a) print("Type = ",type(a))

Output

Complex = (2.75+3.15j)
Type = <class 'complex'>

Python Hexadecimal Type

To represent Octal type (base 16), add a preceding 0x −

Example

a = 0x12 print("Hexadecimal = ",a) print("Type = ",type(a))

Output

Hexadecimal = 18
Type = <class 'int'>

Python Octal Type

To represent Octal type (base 8), add a preceding 0 (zero) −

a = 0O20 print("Octal = ",a) print("Type = ",type(a))

Output

Octal = 16
Type = <class 'int'>

Updated on: 11-Aug-2022

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements