Code for Life
Search…
Python Guide
Python guide for things that have no Blockly equivalence

Outputting text

1
print (‘message’)
Copied!
This will display whatever you put in the place of message in the Rapid Router Output console. You should surround your message with single quotes.

Variables

1
var_1 = ‘Hello!’
2
var_2 = var_1
3
n = 1
Copied!
You can create your own variables using any name except those on the reserved list below. You can assign values to variables using the “=” operator. You can assign the value of one variable to another variable.
You can use the variables anywhere in your program that you would normally use whatever the variable stands for.

Mathematical operators

1
n = 2 + 3
2
n = 23
3
n = 2 * 3
4
n = 2 / 3
Copied!
You can use these with numbers or numeric variables or both.
The examples show addition, subtraction, multiplication and division.
With division, note that the result will be rounded down. For example, the following: n = 5 / 2
The value of n will be 2, not 2.5.

Exit a loop early

1
while condition:
2
break
Copied!
Instead of waiting until condition is no longer True, the break statement will stop executing the loop immediately.

Skip to the next time round the loop

1
for count in range(5):
2
continue
Copied!
Instead of executing the rest of the commands in the loop, this statement will immediately move onto the next time around the loop.

Do nothing

1
pass
Copied!
This statement does absolutely nothing. This is required if you want to define a procedure (or another block such as for or while) that has no other commands.

Reserved words

Reserved words are words that cannot be used as variable or procedure names as they are 'reserved' by Python:
1
and
2
asset
3
break
4
class
5
continue
6
def
7
del
8
elif
9
else
10
except
11
exec
12
finally
13
for
14
from
15
global
16
if
17
import
18
in
19
is
20
not
21
or
22
pass
23
print
24
raise
25
return
26
try
27
while
28
with
Copied!
Last modified 4mo ago