Variable in Python

Posted on


After discussing about a variable in general which exist in this link which is an article with the title of ‘Variable’, this article will discuss about how to discuss further about variable specifically in Python programming language. Basically, there are several types of variable available in Python programming language. Actually, the type of the variable depends on the content, value or data. In other words, the type of the variable depends on the type of the content, value or data exist in the variable.

Variable in Python

In this part, the main discussion is to describe certain aspects about variable in python. The most important part for this part is about how to define the variable itself. Actually, there is some standards, conventions or rules for defining a variable in Python programming language. Specifically, the standards, conventions or rules for defining the name of the variable. Those standards, conventions, or rules exist as in the following description :

  1. Variable name must start by a letter or an underscore. </p

    So, it is very clear that the variable name in Python programming language can only start with two types of characters. Either start it with an underscore or start it with a letter. Thus, for an example the following variable name is a valid one according to the description :


    The above sample is an example of variable name starts with an underscore.

    firstName, lastName

    The next example above is an example for defining several variable names which starts with a letter.

  2. Variable name cannot start with a number.

    It is very clear that this one will complete the explanation for the first one. Since the variable name can only start with underscore and letters, number is out of the question.

  3. Variable name cannot start with any special characters except underscore.

    This is also a complement to complete the explanation exist in the first one. Except the underscore character, any other special characters cannot exist as the first character to start a variable name in Python programming language.

  4. Variable name can only consist of alpha-numeric characters [A through z and 0 through 9] and also underscore character.

    As an additional information, after defining the first character for the character name, the rest of the character arranging the variable name can only be alpha-numeric characters [A-z, 0-9] and underscore character. So, other special characters is not acceptable. For an example : _employee1, productName1, postalCode1

  5. Variable name is case sensitive.

    In other words, every letter with a different case, either it is lowercase or uppercase will be a different variable. For an example : producticodeName, productCodeName.

  6. Variable name cannot contains keywords which is already exist in Python programming language such as if, while, for, etc.

2 thoughts on “Variable in Python

Leave a Reply