What is the naming convention in Python for variable and function names?

后端 未结 13 2285
生来不讨喜
生来不讨喜 2020-11-22 08:50

Coming from a C# background the naming convention for variables and method names are usually either camelCase or PascalCase:



        
13条回答
  •  有刺的猬
    2020-11-22 09:25

    As the Style Guide for Python Code admits,

    The naming conventions of Python's library are a bit of a mess, so we'll never get this completely consistent

    Note that this refers just to Python's standard library. If they can't get that consistent, then there hardly is much hope of having a generally-adhered-to convention for all Python code, is there?

    From that, and the discussion here, I would deduce that it's not a horrible sin if one keeps using e.g. Java's or C#'s (clear and well-established) naming conventions for variables and functions when crossing over to Python. Keeping in mind, of course, that it is best to abide with whatever the prevailing style for a codebase / project / team happens to be. As the Python Style Guide points out, internal consistency matters most.

    Feel free to dismiss me as a heretic. :-) Like the OP, I'm not a "Pythonista", not yet anyway.

提交回复
热议问题