Python 3 -(2) Values and Variables

Python

VALUES:-
     Basically values are the digits or letters used in python to perform certain task.
     These values has different types:
                      1.integer type(int)  
                            eg:-   2,5
                      2.floating point type(float)
                            eg:-   3.0,2.0
                      3.string
                            eg:-    hello everyone !

VARIABLES:-  

             Variable is the location in memory used to store some data(value) or simply,a name that refer    to value.
      
     * The rules of representing a variable is same as writing identifiers.
     * In python,we even don't have to declare the type of the variable,it will handle internally according to the type of value which we assigned to the variable.

   VARIABLE ASSIGNMENT:- 

                        We use assignment operator(=) to assign a value to variable.

          eg :- 1.  a=34                 #here a is a variable and 34 is a value(int) .
                 2.   b=34.0                #here b is the variable and 34.0 is a value(float).
                 3.   c="hello"              #here c is the variable and hello is a value(string).
     
  MULTIPLE ASSIGNMENT:-

          eg:- 1.  a,b,c=34,34.0,"hello"     #here 34 assign to a ,34.0 assign to b,"hello" assign to c.
                 2.   a=b=c="hello"                 #assigning a single value to the multiple variables.

 STORAGE LOCATION:-

                          id is used to print the address of the variable.


          eg:-                  
                 x=3                                                        
                 print(id(x))        #print address of the variable  

          output:- 4720972181

                 y=3
                 print(id(y)                                 
                                                
            
          output:- 4720972181    

      Observation:-
             Here x and y are in same location.if we give another value to the y then it returns another location(address).

Comments

Popular posts from this blog

Python3

Python3 Function Arguments

Python3 File Handling