Data Types in Python


 What is data type?

       Data types are the classification or categorization of data items. It represents the kind of value that tells what operations can be performed on a perticular data.since everything is an object in Python programming, data types are actually classes and variables are instance (object) of these classes.

      Following are the standard or built in data type in python programming:-

  1. Numeric
  2. Sequence Type
  3. Boolean
  4. Set
  5. Dictionary

        Let us discuss with all the data types one by one.

1. Numeric : - In Python numeric data type represent the data which has numeric value.Numeric value can be Integer, Floating Number or even Complex. These valuse are defined as int, float and complex in Python.

Example:-             2,3.8,-5,0 etc.


A. Integer : - 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.

Example :-            2,35684,-21,0 etc.


B. Float :- This value is represented by float class. It is a real number with floating point representation. It is specified  by a decimal point.

Example :-            2.5,358.546 etc.


C. Complex Number : - Complex number is represented by complex class. It is specified as (real part) + (imaginary part)*j.

Example : -                 2+3j


Note :- Variable can hold values of different data types. Python is an dynamically typed language hence we need not define the type of the variable while declaring it. The interpreter binds tha value with it's type.


   If we want to check the type of the variable than Python enables us to check the type of the variable used in the program. Python provide us the type() function which returns the type of the variable passed.

Example : -          a=10
                              b=10.5
                              c=2+4j
                              print(type(a))  
                              print(type(b))
                              print(type(c))


Output :-                  <class 'int'>
                                <class 'float'>
                                <class 'complex'>
                         



     



  

No comments:

Post a Comment