100751 Views
79190 Views
45286 Views
43314 Views
39973 Views
33349 Views
Sync Files on your Pis, with Syncthing
NextCloud
Buddy Jr.
Robot Arms
TherePi - Music Making with a Raspberry Pi
Motion Controlled Arm
Introduction to FreeCAD for Beginners
Building a Robot Arm with Raspberry Pi and PCA9685
Building User Authentication for Static Sites with FastAPI
Mastering Pydantic for Robust Data Validation
Mastering Markdown for Documentation with Jekyll
Introduction to Rust
KevsRobots Learning Platform
50% Percent Complete
By Kevin McAleer, 2 Minutes
a = 1
When we want to store a value we need to use a variable. In the example we looked at above we stored the number 1 in the variable a, we assigned it by using the equals sign.
variable
1
a
When we think about variables, we can imagine they are like little boxes that store things, and we give those boxes names so that it makes referring to them easier. We can put things into the boxes, look whatâs in them or compare whatâs in them with another box.
We could just give our variables a numbered label but that would make it difficult to remember what is in each one. By naming our variables we can easily understand what we expect the variable to contain. For example if we want to storge the age of a person we could use a variable named age.
age
age = 21
MicroPython Facts Like Python, MicroPython variables donât actually store the value, they just point to the thing that does.
Like Python, MicroPython variables donât actually store the value, they just point to the thing that does.
If variables contain values that change, Constants contain values that dont change. For example, if we wanted to store the value of pi, the value of pi does not change, so we can store this in a special type of object called a constant.
variables
Constants
pi
constant
PI = const(3.141592654)
In the example above we use the const() function to define the value 3.141592654 as the constant PI. The convention is that constants are always in uppercase.
const()
3.141592654
PI
Const() const() is a specific to MicroPython, in regular python constants are treated as varibles, just in upper case.
const() is a specific to MicroPython, in regular python constants are treated as varibles, just in upper case.
< Previous Next >