Values

Learn about Steps and Storage before learning this page.

Numbers

Python can calculate arithmetic.

The results of the calculation can be moved into a variable.

Reading a variable can be combined with arithmetic.

A single variable can be modified with arithmetic many times. This example is similar to counting. If all '1' values change to '2', what happens?

Text Strings

Earlier 'socks' and 'shoes' were used in examples. In programming, these are often called "strings". They are called strings because they are multiple letters hooked together one after the other.

The "+" sign can be used to combine strings. This is a bit different than math, because the strings are just hooked together to make a longer string.

Strings can be combined with variables.

The "+" can happen many times.

Strings can be combined with numbers. The "str()" means change the number into a string.

Multiple calculations can happen.

Naming Variables

Naming things is very important in programming. The more that you program, the better you will get at naming things.

There are common forms of names that programmers start to use. Some of these common names are used below.

The previous example code used names like drawer1 and boxA. These are not good names because programmers already know that these are variables that store things.

To store a count of the number of socks, it could be named count. If it was the only variable in the program, this might be ok, although it is difficult to tell what this is counting.

If we also needed to store the count of shoes, then the count variable would not work.

When a program gets more complicated, then names can be similar to other names, and then the variables must be given more descriptive names. You might see all of the following forms of names while programming. It is best to decide which form of name to use in your programs.

It is very important to not have duplicate variables to hold the same thing. Otherwise the count of one of the variables might be changed, and the other variable might not, which can be very confusing.