- Daniel Arbuckle's Mastering Python
- Daniel Arbuckle
- 234字
- 2021-07-02 21:09:41
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.
推薦閱讀
- 軟件安全技術
- C++面向?qū)ο蟪绦蛟O計(微課版)
- Mastering C# Concurrency
- 征服RIA
- Python數(shù)據(jù)分析從0到1
- 一本書講透Java線程:原理與實踐
- 搞定J2EE:Struts+Spring+Hibernate整合詳解與典型案例
- 零基礎學Python編程(少兒趣味版)
- 硬件產(chǎn)品設計與開發(fā):從原型到交付
- Java核心編程
- Python Penetration Testing Essentials
- Spring Boot學習指南:構建云原生Java和Kotlin應用程序
- 從零開始學UI設計·基礎篇
- Mastering R for Quantitative Finance
- Qt編程快速入門