Some tips for writing code about variable naming

python

Single leading underscore:_var

Variables or methods beginning with a single underscore are for internal use only. This convention is defined in PEP 8.

Underscore at the end of the single:var_

Resolve naming conflicts: Sometimes, the most appropriate name of a variable is already occupied by a keyword. Therefore, names like class or def cannot be used as variable names in Python. In this case, you can add an underscore to resolve the naming conflict.

Double leading underscore:__var

The double underscore prefix will cause the Python interpreter to rewrite the attribute name to avoid naming conflicts in subclasses. This is also called name mangling-the interpreter changes the names of variables so that conflicts are not likely to occur when the class is expanded.

Double leading and trailing underscore:__var__

If a name starts and ends with a double underscore at the same time, no name decoration will be applied. Variables surrounded by double underscore prefixes and suffixes will not be modified by the Python interpreter. However, Python reserves names with double leading and double trailing underscores for special purposes. Examples of this are the __init__object constructor, or __call__— it makes an object callable (magic method). It is best to avoid using names beginning and ending with double underscores ("dunders") in your own programs to avoid conflicts with future changes to the Python language.

Independent single underscore: _

By convention, sometimes a single independent underscore is used as a name to indicate that a variable is temporary or irrelevant.

LAST, reference value
error: a possible error of optimizer got an empty parameter list_NLOS的博客-CSDN博客

Guess you like

Origin blog.csdn.net/qq_41554005/article/details/114818973