官术网_书友最值得收藏!

Naming conventions

The overriding rule of Python naming conventions is that the naming style for an object should make it plain how the object is used, not what the object is underneath. This means, for example, that a top-level function, which is called to create new objects and which therefore behaves like a class, should be named like a class.

  • Packages and modules: These should have reasonably short names consisting entirely of lowercase letters, and in the case of modules, underscores.
  • Classes: These should be named with a capitalized first letter and capitals at the start of every new word within the name. This is sometimes also called camel case. Exceptions should be classes and so they should follow the class naming convention, but they should also end with the word Error.
  • Functions, methods, instance variables, and global variables: These all should be lower case, with underscores separating the words. If they are meant to be internal rather than part of the public interface, their names should begin with a single underscore.
    • The first parameter of an instance method should always be named self. Named constant values should be written in all capital letters, with underscores separating the words.

That's it for PEP 8 and the formatting rules that most Python programmers expect other people's code to follow. Now, let's move on to talking about nuts and bolts with a discussion of version control.

主站蜘蛛池模板: 宝应县| 平度市| 洞口县| 逊克县| 法库县| 新余市| 乌鲁木齐市| 清徐县| 新源县| 千阳县| 巫溪县| 都昌县| 壤塘县| 昆山市| 溆浦县| 宜宾县| 黑河市| 西丰县| 兴国县| 永仁县| 沂水县| 布尔津县| 惠安县| 贵德县| 府谷县| 石家庄市| 时尚| 深水埗区| 宁化县| 绥化市| 武强县| 屯留县| 仙居县| 通河县| 和龙市| 容城县| 牡丹江市| 长宁区| 大港区| 建水县| 怀化市|