Python 的代码风格
来源:互联网 发布:阿玛尼手表淘宝 编辑:程序博客网 时间:2024/04/28 12:44
正在看Python3,看到doc里面有一段关于代码风格的说明,摘抄过来大致翻译了下
Use 4-space indentation, and no tabs.
使用4个空格键来实现缩进,不要使用TAB键4 spaces are a good compromise between small indentation (allows greater nesting depth) and large indentation (easier to read). Tabs introduce confusion, and are best left out.
Wrap lines so that they don’t exceed 79 characters.
使用换行控制每行不超过79个字符This helps users with small displays and makes it possible to have several code files side-by-side on larger displays.
Use blank lines to separate functions and classes, and larger blocks of code inside functions.
在函数、类以及函数中的大段代码中插入空白行进行隔离When possible, put comments on a line of their own.
如果可能的话,注释写在对应的行上Use docstrings.
使用DocString 也就是‘’‘或者“”“包含部分Use spaces around operators and after commas, but not directly inside bracketing constructs:a =f(1, 2) +g(3, 4).
在运算符和逗号周边加上空格键,但是不能破坏结构Name your classes and functions consistently; the convention is to useCamelCase for classes and lower_case_with_underscores for functions and methods. Always use self as the name for the first method argument (see A First Look at Classes for more on classes and methods).
大写单词首字母作为类的名称,小写+下划线为函数和方法命名,总是方法的第一个参数名称使用selfDon’t use fancy encodings if your code is meant to be used in international environments. Python’s default, UTF-8, or even plain ASCII work best in any case.
缺省UTF-8,甚至是ASCII作为文件编码Likewise, don’t use non-ASCII characters in identifiers if there is only the slightest chance people speaking a different language will read or maintain the code.
不用使用非ASCII编码的标志符
- Python 的代码风格
- Python--良好的代码风格
- Python代码风格指南
- Python 代码风格
- python代码风格-PEP8
- python代码风格建议
- python代码风格推荐
- Python PEP8代码风格
- Python 代码风格---指南
- python代码风格
- python代码风格
- Python 代码风格指南
- Python代码风格规范
- Python代码风格
- Python 代码风格
- python代码风格
- Python代码风格
- Python 代码风格 和 PEP8
- windows定时器设置
- nios2移植uclinux修改enc28j60驱动成功加入网络
- 40、实例 使用jQuery操作DOM之操作属性
- Unable to chmod ***: Read-only file system问题的解决方法
- 3.13 Anagrams
- Python 的代码风格
- 配置配额系统
- 2014华为机试西安地区B组试题
- 如何在ubuntu14.04(64位)编译运行32位程序
- 2014年7月9日 09:41:58
- js 如何获取最后一个字符(兼容性好 一点的写法)
- 个人安卓学习笔记---初学Activityの简单布局切换
- Unicode 字符编码表|汉字Unicode编码的区间为:0x4E00→0x9FA5(转)
- Perl内建模块UNIVERSAL