Underscore after a variable name in Python

I will decrypt the code of another user and I see the following:

def get_set_string(set_): if PY3: return str(set_) else: return str(set_) 

Does the underscore character AFTER a variable underline anything or is it just part of the variable name and doesn't mean anything?

+7
python naming-conventions
source share
2 answers

No semantics are associated with the final underscore. According to PEP 8 , the Python style guide, users are strongly encouraged to use trailing underscores to ensure they are consistent with the Python and / or Python Embedded keywords:

single_trailing_underscore_ : used by convention to avoid conflicts with the Python keyword, e.g.

Tkinter.Toplevel(master, class_='ClassName')

Using set_ means the built-in name for the sets, i.e. set , will not be obscured and lose a known link during a function call.

+9
source share

This means nothing. I believe that the one who wrote this wanted to name the variable, but set is a type in Python (which creates the set), so he added an underscore.

+4
source share

All Articles