mirror of
https://github.com/pybricks/pybricks-api.git
synced 2026-09-11 09:05:07 +00:00
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:
@@ -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)
|
||||
Reference in New Issue
Block a user