What are Variables?

The word variable in programming describes a place to store information such as numbers, text, lists of numbers and text, and soon. Another way of looking at a variable is that it’s like a label for something.

For example, to create a variable named mark, we use an equal sign = and then tell Python what information the variable should be the label for. Here, we create the variable mark and tell Python that it label’s the number 100 (note that this doesn’t mean that another variable can’t have the same value):

In [2]: mark = 100

Now that we have assigned 100 to mark we would love to find out the value of mark and to find what value a variable labels, enter print in the shell, followed by the variable name in parentheses, like this:

In [2]: print(mark)

Out[2]: 100

Instructor can use more examples to allow the scholars understand more

Variables Names

Variables can have a short name (like x and y) or a more descriptive name (age, carname, total_volume).

But there are few rules for Python variables:

  • A variable name must start with a letter or the underscore character
  • A variable name can never begin with a number
  • A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )
  • Variable names are case-sensitive (age, Age and AGE are three different variables)
  • Python reserved words cannot be used as variables (int, for, if, else, etc)

results matching ""

    No results matching ""