0

I read somewhere that you should avoid using a leading underline in a variable name. It is supposed to have a special meaning in Python. I can't find anything more detailed. Does anybody know?

2
Contributors
1
Reply
3
Views
11 Years
Discussion Span
Last Post by vegaseat
0

Here is an example what the leading _ in a variable name is used for. It will keep a variable private in a module you write. Let's say you write a module ...

# save this simple code as mod_k.py

k = "use me, use me!"
_k = "I am very private!"

... later you used this module ...

# now import your module mod_k.py

from mod_k import *

print k   # displays the value of k from module mod_k
print
print _k  # this will give you an error, _k was private to module mod_k
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.