Numeric Types

In Python, numeric data type represent the data which has numeric value. Numeric value can be integer, floating number or even complex numbers. These values are defined as int, float and complex class in Python.

1) Integers – This value is represented by int class. It contains positive or negative whole numbers (without fraction or decimal). In Python there is no limit to how long an integer value can be.

2) Float – This value is represented by float class. It is a real number with floating point representation. It is specified by a decimal point. Optionally, the character e or E followed by a positive or negative integer may be appended to specify scientific notation.

3) Complex Numbers – Complex number is represented by complex class. It is specified as (real part) + (imaginary part)j. For example – 2+3j

## Example for int type data types

## Specifying the Data type

## Example for float type data types

## Example for complex type data types

## We can create complex numbers from two real numbers. The syntax for doing this is:

## Using isinstance() to check the complex number

sample_integer = 5
print(sample_integer,"is of Type: ", type(sample_integer));print("")

x = int(1234567890123456789)
print("x = ", x, "\nType of x is: ", type(x));print("")

sample_float = 30.5
print(sample_float,"is of Type: ", type(sample_float));print("")

y = float(0.1234567890123456789)
print("y = ", y, "\nType of y is: ", type(y));print("")

complex_num = 3j
print(complex_num,"is of Type: ", type(complex_num));print("")

a = 5
b = 7
c = complex(a,b)
print(c)
print("Type of c is: ", type(c));print("")

z = 1+2j
print(z, "is a complex number?", isinstance(1+2j,complex)) 

Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

thirteen + seventeen =