The single underscore is just a naming convention to state that the property should be considered "semi-private" (similarly double underscore means "private"), but it doesn't have a semantic difference: both versions of the code should behave exactly the same. According to PEP-8:
_single_leading_underscore
: weak "internal use" indicator. E.g. from M import *
does not import objects whose name starts with an underscore.
single_trailing_underscore_
: used by convention to avoid conflicts with a Python keyword.
__double_leading_underscore
: when naming a class attribute, invokes name mangling (inside class FooBar
, __boo
becomes _FooBar__boo
).
__double_leading_and_trailing_underscore__
: "magic" objects or attributes that live in user-controlled namespaces. E.g. __init__
, __import__
or __file__
. Never invent such names; only use them as documented.
If, for some reason, you have a variable prefixed by an underscore and it is acceptable to publicly access this variable, then it is a good practice to include the name of this variable in your module's __all__ list. This serves as a form of in-code documentation.