108640 Views
83860 Views
59555 Views
48723 Views
48311 Views
47806 Views
Build a laser-cut robot
Robots and Lasers
Arduino Plug and Make Kit Review
Pi to Pico W Bluetooth Communication
Two-Way Bluetooth Communication Between Raspberry Pi Picos
Gamepad 2
Introduction to the Linux Command Line on Raspberry Pi OS
How to install MicroPython
Wall Drawing Robot Tutorial
BrachioGraph Tutorial
Intermediate level MicroPython
Introduction to FreeCAD for Beginners
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
str
int
float
complex
list
tuple
dict
set
frozenset
bool
bytes
bytearray
memoryview
NoneType
List of common MicroPython data types with examples
1
2
3
4
-500
1000
3.14
-2.5
1.66666
'hello world'
'my name is Kevin'
[‘cat’,’dog’,’fish’,’gecko’],
[1,2,3,5,8,13,21]
{‘name’:’Kevin’, ‘address’:’UK’, ‘age’:45}
("fish",1,2,3,)
object
'Cat()'
byte
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.
a
integer
b
2.1
c
hello
string
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 a strongly typed language; 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 Python and MicroPython you 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 as weakly typed language. 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
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 a strongly typed language; it helps the compiler allocate the correct amount of memory for the variable before it is used.
C/C++
strongly typed
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 Python and MicroPython you 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 as weakly typed language. 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.
Python
MicroPython
weakly typed
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 of True or False given a set of inputs. These can be expressed as Truth Tables, and is now commonly called Boolean Logic, which is what all modern computing is based upon. Example Truth Table ‘AND’ Logic input a input b output x False False False True False False True True True An AND logic gate has two inputs; a and b and one output x. The table shows each of the possible state the inputs and the outputs can be in. With AND gates both inputs need to be True for the output to be True. This is used a lot in graphics processing too. We will look at logic operators in MicroPython in the Operators lesson.
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 of True or False given a set of inputs. These can be expressed as Truth Tables, and is now commonly called Boolean Logic, which is what all modern computing is based upon.
The Laws of Thought
True
False
Truth Tables
Boolean Logic
‘AND’ Logic
An AND logic gate has two inputs; a and b and one output x. The table shows each of the possible state the inputs and the outputs can be in. With AND gates both inputs need to be True for the output to be True. This is used a lot in graphics processing too.
AND
x
We will look at logic operators in MicroPython in the Operators lesson.
< Previous Next >