前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >python开发_python代码风格(coding style)

python开发_python代码风格(coding style)

作者头像
Hongten
发布2018-09-13 13:47:53
6570
发布2018-09-13 13:47:53
举报
文章被收录于专栏:Hongten

我们要做python开发,我想python中的代码风格我们有必要了解一下

这样对我们自己和他们所编写的代码都有好处的。

下面是8点重要代码风格注意事项:

代码语言:javascript
复制
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.
代码语言:javascript
复制
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.
代码语言:javascript
复制
THREE :  Use blank lines to separate functions and classes, and larger blocks of code inside functions. -- 在函数或者类中使用空白行
代码语言:javascript
复制
FOUR :  When possible, put comments on a line of their own.--添加注释,这个可以帮助你自己和他人阅读代码
代码语言:javascript
复制
FIVE :  Use spaces around operators and after commas, but not directly inside bracketing constructs: a = f(1, 2) + g(3, 4).--在编写代码的过程中,注意使用空格,这样使得你的代码看上去清晰,美观
代码语言:javascript
复制
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 '这样的方式命名方法或者函数
代码语言:javascript
复制
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的编码方式进行编码
代码语言:javascript
复制
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字符标识符
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2013-07-27 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档