Chapter 1.7 - Variables

So what is a variable? Variable is a container. And what it contains? It can contain almost everything from numbers (integer, floating or complex) to strings

Variables should start with a lower case letter. They can start with an upper case or an underscore but you should not do it in normal basis. After the first lower case letter, the variable may include uppercase and lowercase letters, along with numbers and underscores. Variables may not include spaces.

Variables are case sensitive. This can be confusing if a programmer is not expecting it. In the code below, the output will be 6 rather than 5 because there are two different variables, x and X.

x = 6
X = 5
print(x)
print(X)

There are some rules for naming variables but it is not something that we should always follow.

Check the table below and think what are the rules for naming.


Variable Names
Legal Variable Names       Illegal Variable Names      Legal but not proper     
first_name first name FirstName
distance 9ds firstName
ds9 %correct D9

All upper-case variable names like MAX_SPEED are allowed only in circumstances where the variable's value should never change. A variable that isn't variable is called a constant.