Python Data Types

Data Types

In python we don't need to define the type of variable while declaring it. python provide us to know the type of Data using  type()  function.

For Example :

      >>> a = 10
      >>> b = 'ProgGeek'
      >>> c = 1.1
      >>> print(type(a))
      <class 'int'>
      >>> print(type(b))
      <class 'str'>
      >>> print(type(c))
      <class 'float'>
      >>> 

Standart Data Type

  • Variables can hold different data type of values. for Example age must be stored in integer where name must be stored in string
  • python provide us different data types: 
  1. Numbers
  2. String
  3. List
  4. Tuples
  5. Dictionary

1.Numbers :

  •  Number store numeric value.
  • python support 4 types of numeric data type.
  1. int
  2. float 
  3. long
  4. complex  (a+bj)

2.String :

  • String can string sequence of character 
  • The ' + ' operator is used to concatenate two string.
            >>> print('prog' + 'geek')
     proggeek
  • the  ' * '  operator is used to repetition of string.
     >>> print('ProgGek' * 2)
     ProgGekProgGek
  • printing Substring.
     >>> str = 'Proggeek'     
     >>> print(str[0:2])
     Pr
         
            using this technique we will print multiple substring
  • print single character.
     >>> str = 'Proggeek'     
     >>> print(str[0])
     P
     
    printing single character from string is done by using indexing

3.List : 

  • list are similar to array.
  • list can contain data of different data type.
  • list are separated with a comma ( , ) and enclosed with brackets [ ].
     >>> list = [100,"prog"] 
     >>> print(list)
     [100, 'prog']

4.Tuples : 

  • tuples is similar to the list.
  • tuples can contain data of different data type.
  • tuples are separated with a comma ( , ) and enclosed with parentheses ( ).
     >>> tuples= (1,"proggeek")
     >>> print(tuples)
    (1, 'proggeek')

5.Dictionary : 

  • Dictionary is set of key-values pair of item.
  • the item of  Dictionary  are separated with a comma ( , ) and enclosed with braces {  }.
     >>> dict  = {1 : "prog" , 2 : "Geek" }
     >>> print(dict)
     {1: 'prog', 2: 'Geek'}
     >>> print(dict.values())
     dict_values(['prog', 'Geek'])
     >>> print(dict.keys())
     dict_keys([1, 2])
     >>> 
     

Comments