What's the advantage of a trailing underscore in Python naming?

Exactly what it gives in the PEP: it allows you to use something that would otherwise be a Python keyword.

as_
with_
for_
in_

PEP8 does not recommend this naming convention, except for names that would otherwise conflict with keywords. my_argument obviously does not conflict, so there is no reason to use an underscore and PEP8 does not recommend that you do.


Usually naming conventions like this don't have any empiric purpose in python (i.e. they don't do anything special) aside from avoiding conflict between keywords. For example, you wouldn't name a variable class would you? You'd name it class_ to avoid conflict with the built-in keyword.