variables starting with underscore
-
Why is it that in the REPL, the following works
>>> c = const(10) >>> c 10
but the following does not work
>>> _c = const(10) >>> _c Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name '_c' is not defined
? However, this works when make a script and execute it with a
print(_c)
statement. It will indeed print10
.
-
MIcropython works a little different than python.
In python you use the underscrore in front of variable to mark the variable as private. Nut it is still visible. In micropython these are real local variables an will not be exported. So a class will have a memory footprint which is slightly lower.
The micropython page had this info once under the optimization part. I cannot find it right now. Maybe you have to play around with the version settings in the documentation.