:int in micropython #18441
Replies: 2 comments 2 replies
-
|
These are type hints and are supported by MicroPython. See, for example, this tutorial. |
Beta Was this translation helpful? Give feedback.
-
|
Technically "type annotations" , but there are often mixed up, no harm done. Note that while MicroPython supports the syntax, it removes all type annotations during compilation to bytecode. So these type annotations cannot be used during runtime. They are still useful to better understand the code and types of parameter passed in. And tools such as pyright, mypy and vscode can help you prevent errors using such info. Also for humans, if you need to call a function such as: def parrot(t,x):
...
def ara(t:str, x:int | None):
...Shameless plug , and much more details wrt MicroPython https://micropython-stubs.readthedocs.io |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi all,
I found some (working) code by Tim Hanewich, running on the raspberry pi pico:
https://github.com/TimHanewich/Air-Quality-IoT?tab=readme-ov-file
There are several instances of code such as
"humidity:float = rht[0]" and
"aqi:int = ens.AQI"
I was unable to find any references to using ":int" or ":float" in micropython. The code works...
many thanks for your insights...
Tom
Beta Was this translation helpful? Give feedback.
All reactions