python开辟_python代码风格(coding style)
添加时间:2013-7-27 点击量:
我们要做python开辟,我想python中的代码风格我们有须要懂得一下
如许对我们本身和他们所编写的代码都有益处的。
下面是8点首要代码风格重视事项:
ONE : 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.
TWO : 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.
THREE : Use blank lines to separate functions and classes, and larger blocks of code inside functions. -- 在函数或者类中应用空白行
FOUR : When possible, put comments on a line of their own.--添加注释,这个可以帮助你本身和他人浏览代码
FIVE : Use spaces around operators and after commas, but not directly inside bracketing constructs: a = f(1, 2) + g(3, 4).--在编写代码的过程中,重视应用空格,如许使得你的代码看上去清楚,美观
SIX : Name your classes and functions consistently; the convention is to use CamelCase for classes and lower_case_with_underscores for functions and methods. Always use self as the name for the first method argument --应用驼峰定名法定名类名;应用lower_case_with_underscores 如许的体式格式定名办法或者函数
SEVEN : Don’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的编码体式格式进行编码
EIGHT : 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中的代码风格我们有须要懂得一下
如许对我们本身和他们所编写的代码都有益处的。
下面是8点首要代码风格重视事项:
ONE : 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.
TWO : 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.
THREE : Use blank lines to separate functions and classes, and larger blocks of code inside functions. -- 在函数或者类中应用空白行
FOUR : When possible, put comments on a line of their own.--添加注释,这个可以帮助你本身和他人浏览代码
FIVE : Use spaces around operators and after commas, but not directly inside bracketing constructs: a = f(1, 2) + g(3, 4).--在编写代码的过程中,重视应用空格,如许使得你的代码看上去清楚,美观
SIX : Name your classes and functions consistently; the convention is to use CamelCase for classes and lower_case_with_underscores for functions and methods. Always use self as the name for the first method argument --应用驼峰定名法定名类名;应用lower_case_with_underscores 如许的体式格式定名办法或者函数
SEVEN : Don’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的编码体式格式进行编码
EIGHT : 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字符标识符
我们永远不要期待别人的拯救,只有自己才能升华自己。自己已准备好了多少容量,方能吸引对等的人与我们相遇,否则再美好的人出现、再动人的事情降临身边,我们也没有能量去理解与珍惜,终将擦肩而过。—— 姚谦《品味》