Python Data Type with example and explanation by ShadBox

Total Blog Views: 50

Blog Status: publish

Created By: swazahmad Created at: 07-16-2021

Tags: python datatype basicprogramming web development

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])
     >>> 
 
     


swazahmad

Swaz is Practice Lead of ROR Developer. he's a Blogger, Mentor, and Rubyst. He has expertise in Javascript also . he's highly skilled in designing, developing and testing web applications. He enjoys being challenged and interesting with projects that need him to



Comments



  • swazahmad | almost 4 years ago
    Awesome Information Thanks For Sharing
Buy traffic for your website

About Shadbox

we have the “Get things executed” lifestyle at our place of work. There are not any excuses, no if’s or however’s in our dictionary. committed to navigating the ship of creativity to create cell answers, we resolve the real-lifestyles troubles of our clients and their clients. Our passion for work has won us many awards, year after 12 months.

Services

Downloads