Python Variables

Python Variables

Python Variables

Python Variable is a name which is utilized to allude memory area. Variable otherwise called identifier and used to hold data. 

In Python, we don't have to indicate the kind of factor since Python is a sort of induce language and sufficiently brilliant to get variable sort. 

Variable names can be a gathering of the two letters and digits, yet they need in any case a letter or an underscore. 

It is recommended to utilize lowercase letters for a variable name. John and john both are two distinct factors. 


Identifier Naming 

Factors are the case of identifiers. An Identifier is utilized to recognize the literals utilized in the program. The tenets to name an identifier are given underneath. 


  • The first character of the variable must be a letter in order or underscore ( _ ). 
  • Each of the characters aside from the primary character might be a letter in order of lower-case(a-z), capitalized (A-Z), underscore or digit (0-9).
  • Identifier name must not contain any void area, or extraordinary character (!, @, #, %, ^, and, *). 
  • Identifier name must not be like any catchphrase characterized in the language. 
  • Identifier names are case sensitive for instance name, Name, and NAME isn't the equivalent. 
  • Instances of valid identifiers : a123, _n, n_9, and so on. 
  • Instances of invalid identifiers: 1a, n%4, n 9, and so on. 

Declaring Python Variable and Assigning Values 

Python does not bound us to pronounce variable before utilized in the application. It enables us to make a variable at a required time. 

We don't have to announce expressly factor in Python. When we dole out any an incentive to the variable that variable is proclaimed consequently. 

The equivalent (=) administrator is utilized to dole out an incentive to a variable.


Python Variables

Example:


    >>> no=5
      >>> ch='r'
        >>> name="sk jha"
          >>> fl=45.67
          >>>
            >>> print("number=",no)
              number= 5
                >>> print("char=",ch)
                  char= r
                    >>> print("name=",name)
                      name= sk jha
                        >>> print("float=",fl)
                          float= 45.67
                            >>> 


                            Multiple Assignments

                            Python allows us to assign a value to multiple variables with the same data at a time which is also known as multiple assignments.

                            We can apply multiple assignments in two ways either by assigning a single value to multiple variables or assigning multiple values to multiple variables. Let's see the examples.

                            1. Assigning single value to multiple variables
                            Example:
                            1. a=b=c=100  
                            2. print a 
                            3. print b  
                            4. print c  
                            Output:
                            1. >>>   
                            2. 100  
                            3. 100  
                            4. 100  
                            5. >>>  


                            2.Assigning multiple values to multiple variables:
                            Eg:
                            1. a,b,c=50,100,500  
                            2. print a  
                            3. print b  
                            4. print c  
                            Output:
                            1. >>>   
                            2. 50  
                            3. 100  
                            4. 500  
                            5. >>>  
                            The values will be assigned in the order in which variables appears.



                            Python Variables Python Variables Reviewed by Sk Jha on January 04, 2019 Rating: 5

                            No comments:

                            Powered by Blogger.