Python PEP8 PEP257 编码规范中文版 学习笔记
2018-12-15 15:33
363 查看
原文链接:http://legacy.python.org/dev/peps/pep-0008/
A Foolish Consistency is the Hobgoblin of little Minds.
尽信书不如无书
与PEP8一致的目录
PEP8
1.缩进用4个空格,尽量不用TAB键
2.行最大字符79,注释字符最大72
3.推荐在二元操作符之前换行
# 推荐:运算符和操作数很容易进行匹配 income = (gross_wages + taxable_interest + (dividends - qualified_dividends) - ira_deduction - student_loan_interest)
4.import导入通常在分开的行,
# 推荐这样 import os import sys # 不推荐: import sys, os # 但是可以这样: from subprocess import Popen, PIPE
5.程序顶部顺序
# 1.模块注释和文档字符串 """ 模块注释和文档字符串在最上面 """ # 1.1 __future__这个特例 from __future__ import barry_as_FLUFL # 2 模块级的呆名 __author__ = 'junqiao' __version__ = '0.1' # 3.1标准库的导入 # 3.2相关第三方库的导入 # 3.3本地库的导入 import os import operate import numpy import xadmin import mylibrary # 4 变量的定义 myList = []
6.python中单引号和双引号等价
7.避免在尾部添加空格
8.考虑在二元运算符两边加空格,例如 = , + , - , += , ==, and
但是在使用不同优先级的运算符时,考虑在最低优先级的运算符周围添加空格
# 推荐: i = i + 1 submitted += 1 x = x*2 - 1 hypot2 = x*x + y*y c = (a+b) * (a-b)5 #不推荐: i=i+1 submitted +=1 x = x * 2 - 1 hypot2 = x * x + y * y c = (a + b) * (a - b)
在制定关键字参数或者默认参数值时,不要在=附近加上空格
#推荐: def complex(real, imag=0.0): return magic(r=real, i=imag) #不推荐: def complex(real, imag = 0.0): return magic(r = real, i = imag)
9.插曲 函数参数注解
# 参数x y return 为int型,但只是注释, #如果用错,定义时不报错,执行时才会报错 def accumlate(x:int, y:int) -> int: return x*y
PEP257 规范书写文档
相关文章推荐
- Python学习笔记(8):Python PEP8编码规范
- Python PEP8 编码规范中文版
- Python PEP8 编码规范中文版
- 学习 python 编写规范 pep8 的问题笔记
- 学习 python 编写规范 pep8 的问题笔记
- Python PEP8 编码规范中文版
- 学习 python 编写规范 pep8 的问题笔记
- Python学习笔记 --- Python 编码规范
- Python PEP8 编码规范中文版
- PEP8 Python 编码规范整理
- Python(7) 编写规范 pep8 的问题笔记
- python学习笔记--关于编码
- 【学习笔记】JavaScript编码规范-语句块
- python学习笔记day6:内存地址以及编码小结
- PEP8 Python 编码规范
- PEP8 Python 编码规范
- python_基础学习_命名规范/编码/注解
- PEP8 Python 编码规范
- PEP8 Python 编码规范整理
- PEP8 Python 编码规范