Sei sulla pagina 1di 2

SECTION 1 – THINGS TO REMEMBER IN PYTHON

Strings are text in python. When


printing them you must put them in
brackets and surround them with
quotation marks. The same does not
apply for if statements.

Put a colon after an if statement.


After a colon,
put a full tab This is a comparison operator. It could
space as an also be: !=, <>, >, <.
indent. This
command This is a variable, it has been defined.
All variables must be defined, we use
executes when
the statement is an = sign for this.
true.

SECTION 2 – LOOPS IN PYTHON

In this for loop, the variable “i” is assigned to the first value in the range, this is then printed in the
second line. Next, the “i” variable picks up the second value which is then printed. This process is
repeated until the end of the range. This would altogether produce:

In this loop, “var_x” starts as zero, which is less than 100. So the next line is executed and the print
statement is called. The next line adds 1 to “var_x”. As this is the end of the loop, x is once again
checked to see if it is less than 100. This cycle is then continued until var_x = 99. This would
altogether produce:

This repeats even more


until “var_x” = 99
3

In this loop variable values, text and a calculation are concentrated (joined) in one line. The text
(strings are contained between the quotes in green. The commas are used to concentrate the
different elements of code. In the print statement the first “var_x” gives its value, and the “y*x”
does the calculation. This would altogether produce:

Notice that its like a times


table

SECTION 3 – ARRAYS IN PYTHON

This is an array variable. Array variables are variables that contain other variable. If I printed this
array, it would look like this:

But if I add a for loop like this:

The end result would print vertically like this:

Potrebbero piacerti anche