This appendix provides a reference for some of the key features and functions available in MicroPython. Treat it as a reference resource, and try out some of the functions to see how they work. The REPL is your friend. Try things out. For full details on everything in Python, go to https://microbit-micropython.readthedocs.io/en/latest/.
Table A-1 shows some of the functions you can use with numbers.
To test to see whether two values are the same, we use ==
. This is called a comparison operator. The comparison operators that we can use are shown in Table A-2.
Table A-3 shows some of the functions you can use with numbers.
String constants can be enclosed either with single quotes (most common) or with double quotes. Double quotes are useful if you want to include single quotes in the string like this:
There are other occasions when you may want to include special characters such as
end-of-lines or tabs in a string. To do this, you use what is called escape characters that begin with a backslash (\
). The only ones that you are likely to need are
\t
—tab character
\n
—new line character
Table A-4 lists some of the strings functions that may be useful.
Table A-5 summarizes the common List functions.
Table A-6 lists some common Dictionary functions.
Table A-6 Dictionary Functions
Python contains a number of built-in functions for converting things of one type to another. These are listed in Table A-7.