freeCodeCamp/guide/chinese/python/python-coding-standards/index.md

30 lines
1.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

---
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
```
这将提供违反标准的所有行,以及修复的简短描述。