micropython.const: Improve docstring, add example.

This merges the useful information from two different places:
- The original docstring for const.
- Writing MicroPython code for constrained devices.

Also reduce type to just int, because only ints are supported.
This commit is contained in:
Laurens Valk
2021-07-14 14:48:59 +02:00
parent c656eae2f3
commit 4c00c3209b
3 changed files with 29 additions and 17 deletions
+13
View File
@@ -0,0 +1,13 @@
from micropython import const
# This value can be used here. Other files can import it too.
APPLES = const(123)
# These values can only be used within this file.
_ORANGES = const(1 << 8)
_BANANAS = const(789 + _ORANGES)
# You can read the constants as normal values. The compiler
# will just insert the numeric values for you.
fruit = APPLES + _ORANGES + _BANANAS
print(fruit)