Python Variables

           

Variables 


variables are used to refer memory location. memory is used to hold the values. In python we don't need to specify the types of variables because python is a type infer language and smart to get variable type.

variable names can be  a group of digit and alphabet ,but they have to begin with a letter or an underscore. 

  • the first character of variable  must be an alphabet or underscore.
  • variables not contain any white-space (space) or special character (! , @ , # , $ , % , etc)

 Declaration Variable and Assigning Values  

we don't need to declare explicitly variable in python. when we assign any value to variable that variable is declare automatically.  

Example : 


    >>> a =100
    >>> print(a)
    100
    >>> a= 'ProgGeek'
    >>> print(a)
    ProgGeek
    >>> 

Multiple Assignment 

Python allows to assign multiple variable in single statement.

Examples :


  • Assign single value in multiple variables
        
     >>> a=b=c=100
     >>> print(a,b,c)
     100 100 100
     >>> 


  • Assign multiple values in multiple variables

     >>> a=b=c=100,200,300
     >>> print(a,b,c)
     100 200 300
     >>> 


Comments