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?

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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.