KevsRobots Learning Platform
60% Percent Complete
By Kevin McAleer, 5 Minutes

Programs often need to work with numbers and text, adding and subtracting, asking questions and processing answers.
MicroPython is able to label different types of values so that it can make different commands available to us.
The different types of values are listed below:
List of MicroPython data types
| Text type: | str |
| Numeric types: | int, float, complex |
| Lists and sequences: | list, tuple |
| Dictionaries (mapping of key-value pairs) | dict |
| Set types: | set, frozenset |
| True/False (Boolean) type: | bool |
| Binary types: | bytes, bytearray, memoryview |
| None type: | NoneType |
List of common MicroPython data types with examples
| Value Types | Description | Example |
|---|---|---|
int |
A whole number, which can be positive or negative | 1, 2, 3, 4, -500, 1000 |
float |
A decimal number, which can be positive or negative | 3.14, -2.5, 1.66666 |
str |
A line of text | 'hello world', 'my name is Kevin' |
list |
A collection of words or numbers, or objects, (with no duplicates) | [βcatβ,βdogβ,βfishβ,βgeckoβ], or [1,2,3,5,8,13,21] |
dict |
A dictionary - a list, with pairs of values | {βnameβ:βKevinβ, βaddressβ:βUKβ, βageβ:45} |
tuple |
A collection of ordered items, can have duplicates | ("fish",1,2,3,) |
object |
An instance of a class (weβll cover this in a later session) | Object of 'Cat()' Class |
byte |
A single 8 bit byte, which is a value between 0 and 255 | 255, '0xFF', '0b11111111' |
Note The more complex data types have been excluded from this list. Weβll look at them in more detail in later modules.
When we assign a value to a variable, it is said to have the a type. e.g.
a = 1
b = 2.1
c = "hello"
In this example a contains the value 1 and is of type integer, b contains the value 2.1 and is of type float (because it has a decimal point), and c contains hello and is of type string because it contains a text wrapped inside some speech marks.
Implied Types
In other languages, such as
C/C++you will need to tell the compiler what kind of datatype a variable is before it is used. This is known as astrongly typedlanguage; it helps the compiler allocate the correct amount of memory for the variable before it is used.C++ Example
int a; // tells the compiler that 'a' is an integer float b; // tells the compiler that 'b' is a floating point number a = 1; b = 2.3;
In
PythonandMicroPythonyou do not need to assign a type to a variable, Python is smart enough to figure this out by the value being assigned to it. This is known asweakly typedlanguage. The trade off is that Python looks cleaner to read and doesnβt need data types to be assigned before theyβre used, however this can lead to confusion if another type of value is expected or assigned to a variable of a differnet type.MicroPython Example
a = 1 # python knows that 1 is an integer value so 'a' becomes an 'int' type b = 2.3 # python knows that 2.3 is a floating point value so 'b' becomes a 'float' type
George Boole the Father of Boolean Logic
English mathematician and logician George Boole was the author of
The Laws of Thought(1854) which documents the algebra of logic. He founded the idea that logic can be expressed in a series of symbols that show an output ofTrueorFalsegiven a set of inputs. These can be expressed asTruth Tables, and is now commonly calledBoolean Logic, which is what all modern computing is based upon.
Example Truth Table
βANDβ Logic
input a input b output x False False False TrueFalse False TrueTrueTrueAn
ANDlogic gate has two inputs;aandband one outputx. The table shows each of the possible state the inputs and the outputs can be in. WithANDgates both inputs need to beTruefor the output to beTrue. This is used a lot in graphics processing too.We will look at logic operators in MicroPython in the Operators lesson.
You can use the arrows β β on your keyboard to navigate between lessons.
Comments