Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
442 views
in Technique[技术] by (71.8m points)

namespaces - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

as_
with_
for_
in_

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...