0

Sometimes I need to use variable name like max, or len, but they are somehow occupied by the python library method. Should I instead just use _max or max_?

What is the conversion for these variable naming style?

3
  • 2
    make it more specific. if it's a maximum length, use maxlen or something like max_length. If it's the length of something, use length. Don't use weird underscores :P Commented Oct 27, 2017 at 0:16
  • underscores have implicit meaning in python, see hackernoon.com/… Commented Oct 27, 2017 at 0:19
  • 1
    The convention is to use a trailing underscore: max_ or len_ Commented Oct 27, 2017 at 0:24

2 Answers 2

1

From pep8 official documentation:

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

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

Sign up to request clarification or add additional context in comments.

Comments

0

There's no such convention, at least not in PEP 8, what is mentioned in PEP 8 that may apply is the following:

If a function argument's name clashes with a reserved keyword, it is generally better to append a single trailing underscore rather than use an abbreviation or spelling corruption. Thus class_ is better than clss. (Perhaps better is to avoid such clashes by using a synonym.)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.