Chapter 1

Expressions

In Python, you can assign variables with the “=” sign. For example, if you want to assign the number 10 to the variable x, you would type the following into your interpreter:

x=5

This variable is now stored in memory, and can be called.

x
Out:

5

You can also include this variable in other expressions.

x+6
Out:

11

Notice that the expression above has both values (x and 5) and an operator (+). Expressions reduce down to a single value (in this case 11). The value from an expression can also be assigned to a variable.

y = x+6
y
Out:

11

Variable Naming Convention

Variable names in python must follow the following rules:

  1. Variables can only contain letters, numbers, and underscores (_).
  2. Variables cannot start with a number.

The following are appropriate variable names:

The following are not appropriate variable names:

The name of a variable is what’s called an identifier. Python identifiers are also used functions, classes, modules, etc. They also follow the same rules listed above. Identifiers are case senstive, meaning if we can define different values to clown and CLOWN as seen below.

clown = 10
CLOWN = 15

print("clown: "+str(clown))
print("CLOWN: "+str(CLOWN))
Out:

clown: 10
CLOWN: 15

In Python, there are also reserved words. These are words that cannot be used as identifiers:

Intro to Data Structures

In this section, I will introduce three basic data structures: integers, floats, and strings. More data structues will be introduced in the next chapter.

Integers