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

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.

主站蜘蛛池模板: 大余县| 开化县| 镇原县| 海南省| 北票市| 体育| 南安市| 镇巴县| 桃源县| 土默特左旗| 吉林省| 汉寿县| 资兴市| 兖州市| 铜川市| 田阳县| 黄石市| 金堂县| 陕西省| 武隆县| 泗水县| 襄垣县| 改则县| 永丰县| 繁峙县| 河间市| 姚安县| 西峡县| 赤峰市| 永丰县| 安顺市| 阿合奇县| 开封县| 保康县| 阳谷县| 麟游县| 贡嘎县| 玛纳斯县| 江孜县| 远安县| 宜春市|