variables starting with underscore
-
Why is it that in the REPL, the following works
>>> c = const(10) >>> c 10but 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.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login