30 lines
1.2 KiB
Markdown
30 lines
1.2 KiB
Markdown
---
|
||
title: Coding standards
|
||
localeTitle: 编码标准
|
||
---
|
||
### 大纲
|
||
|
||
* 为什么编码标准?
|
||
* PEP 8简介
|
||
* 命令
|
||
|
||
### 为什么编码标准?
|
||
|
||
全球python社区正在快速增长,几乎每个人都使用python。这是代码和统一标准的可读性很重要的地方。地球上的任何人都应该能够阅读您的代码并了解它的作用。理解其他代码有很多方面,例如关于函数功能的评论,逻辑上在模块和函数之间划分任务,良好的变量名称等。
|
||
|
||
### PEP 8简介
|
||
|
||
我们喜欢坚持惯例。 python用户社区已经提出了一套标准,现在这些标准被视为惯例。您编写的任何行业级代码都通过PEP 8检查程序运行。因此,开始为您的类和函数编写文档字符串,并使用approrpiate下划线以小写字母命名变量是一种很好的做法。在开始编码之前,看看这些标准可能是值得的。
|
||
|
||
[这是详尽的链接](https://www.python.org/dev/peps/pep-0008/ "PEP 8标准")
|
||
|
||
### 命令
|
||
|
||
这是你如何检查你的python代码是否符合他的标准。
|
||
|
||
```console
|
||
:~$ pip install pep8
|
||
:~$ pep8 --first myCode.py
|
||
```
|
||
|
||
这将提供违反标准的所有行,以及修复的简短描述。 |