Python Numeric datatypes

The numeric datatypes are used to store numerical values. Python numeric datatype includes the following four number types.

Python Numeric datatypes

The numeric datatypes are used to store numerical values. Python numeric datatype includes the following number types:

  • int  – holds signed integer values.
  • long – can hold long integer values.
  • float – holds floating point values.
  • complex – holds complex numbers.

1) int

An integer is a signed whole number.

Example

a=10
b=-26
c=12345678910
print(type(a))
print(type(b))
print(type(c))

Output

<class 'int'>
<class 'int'>
<class 'int'>

2) float

The float numeric type can hold signed decimal numbers.

Example

a=10.5
b=-26.5
print(type(a))
print(type(b))

3) complex

In Python, ‘j’ indicates the imaginary part of a complex number.

Example

a=10j
b=-26.5j
print(type(a))
print(type(b))

Output

<class 'complex'>
<class 'complex'>

Learn about other datatypes in Python.


Share Tweet Send
Loading...