105800 Views
82496 Views
47243 Views
47066 Views
45458 Views
38527 Views
Pi-Apps
Intermediate MicroPython
Arduino Alvik
Raspberry Pi Time machine
Now Ad-Free
Guiding Light
Intermediate level MicroPython
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
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 >