standard data types in python.

Variable can hold different values like emp_id as number , emp_name as string.

Python provide various standard data types as follows.

1-Number

2-String

3-List

4-Touple

5-Dictionary


1-Number

Number store numeric value. When you are going to assign the numeric value to a variable python create a Number object.

Python has 4 types of numeric data.

1-int(signed integer values like 10 , 20 etc.)

2-long(It is used to stored higher range values like 99999999999L etc.)

3-float(It is used to stored floating value like 20.5 etc.)

4-complex(complex number like 20.13j,20+3.12j)


2-String

String is a sequece of character with in quote marks. We can use single , double or triple quote marks to define the string in python.

The + operator is used to concatenate the two string like "hello"+" python" returns "hello python".

The * operator is used to repetition task like "python "*2 returns "python python"

      str1="hello python"
      str2="how are you"
      print(str1[0:3])  #print the first three character
      print(str[4])     #print the fourth charcater
      print(str1+str2)  #print the concatenation of str1 and str2 
      print(str1*2)     #print the hello python twice          
    
    OUTPUT : Hel
             o
             hello python how are you
             hello python hello python
    

3-List

Python list is very similar to array in c , c++ , java etc. List contains the different data types values. The list items are seperated with comma(,) and enclosed with in square bracket[].

We can use the slice operator[:] to access the items from list. The + operator and * operator work with list same way as work with strings.

      l=[1,"hi","abhi",3]   # this is list stored the 4 items
      print(l)              # print all the item of list
      print(l[0:2])
      print(l[3:])
      print(l+l)          
      print(l*2)
    
    OUTPUT : [1 ,'hi' , 'abhi' , 3]
             [1 , 'hi']
             [3]
             [1 ,'hi' , 'abhi' , 3 , 1 ,'hi' , 'abhi' , 3]
             [1 ,'hi' , 'abhi' , 3 , 1 ,'hi' , 'abhi' , 3]
    

4-Tuple

Python tuple is very similar to list. The list and tuple both contains the different data types values. The tuple items are seperated with comma(,)and enclosed with in parentheses ().

Tuple is read only you can not modify the items of tuple.

      t=[1,"hi","abhi",3]   # this is tuple stored the 4 items
      print(t)              # print all the item of list
      print(t[0:2])
      print(t[3:])
      print(t+t)          
      print(t*2)
    
    OUTPUT : [1 ,'hi' , 'abhi' , 3]
             [1 , 'hi']
             [3]
             [1 ,'hi' , 'abhi' , 3 , 1 ,'hi' , 'abhi' , 3]
             [1 ,'hi' , 'abhi' , 3 , 1 ,'hi' , 'abhi' , 3]
    

5-Dictionary

Python dictionary is used to stored the items in key value pairs. The items are seperated with comma(,) and enclosed with in curly brackets{}.

Tuple is read only you can not modify the items of tuple.

di=[1:"Abhi",2:"Rakesh",3:"Amit"] # this is dictionary stored the 3 items
print(di)                         # print all the item of dictionary
print("Name is"+di[1])
print("Name is"+di[2])
print("Name is"+di[3])
print(di.keys)         # print all the keys
print(di.values)       # print all the values
    
    OUTPUT : {1:'Abhi',2:'Rakesh',3:'Amit'}
             Name is Abhi
             Name is Rakesh
             Name is Amit
             [1,2,3]
             ['Abhi','Rakesh','Amit']
           
    

Welcome to AndroidATPoint.

Smiley face                     Smiley face