Skip to content
Advertisement

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

I am used to naming Python arguments in this way:

my_argument='foo'

what’s the advantage if I do this instead:

my_argument_='foo" 

as is recommended by PEP008?

There must be a good reason for the trailing underscore, so what is it?

Advertisement

Answer

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

as_
with_
for_
in_
Advertisement