Python Numeric data type

  • The power of a programming language depends, among other things, on the range of different types of data it can handle.
  • There are three numeric types in Python:

    • int
    • floating-point
    • complex
    • Boolean
Example
x = 5    # int
y = 3.8  # float
z = 5j   # complex

int

  • Using the Int, or integer, is a whole number, positive or negative, without decimals, of unlimited length.
Example
x = 11
y = 39574585744887711
z = -74855522

print(type(x))
print(type(y))
print(type(z))

Float

  • A float, or “floating-point number” is a number, positive or negative, containing one or more decimals.
Example
x = 2.10
y = 3.0
z = -55.59

print(type(x))
print(type(y))
print(type(z))

Complex

  • Complex numbers are the imaginary part.
  • it can write with a “j”  in python.
Example
x = 4+5j
y = 6j
z = -9j

print(type(x))
print(type(y))
print(type(z))

Find the Data Type

 type() function: using this function get the data type of any object or variable.

Example
y = 15
print(type(y))
Example
x = 1
y = 2.8
z = 1j

print(type(x))
print(type(y))
print(type(z))
"""Output 
<class 'int'>
<class 'float'>
<class 'complex'>
"""

Boolean

  • Boolean data types return the always True or False results
Example

Use of boolean data types

a=5
b=10
print(a>b)

Output

False
English Hindi