摘自google.

https://i.cnblogs.com/PostDone.aspx?postid=9753605&actiontip=%E4%BF%9D%E5%AD%98%E4%BF%AE%E6%94%B9%E6%88%90%E5%8A%9F

1、缩进

    Tip

    用4个空格来缩进代码

2、代码太长:      

  如果一个文本字符串在一行放不下, 可以使用圆括号来实现隐式行连接:

  x = ('This will build a very long long '
'long long long long long long string')
或者:

  print \\

"hello world!"

3、类:

class SampleClass(object):

4、注释:

"""Explicitly inherits from another class already."""

或者

#Explicitly inherits from another class already.

5、字符串:

通常可以用+,%,join(), format 三个函数进行处理

%s   #字符串

%d  #数字

Yes: x = a + b
x = '%s, %s!' % (imperative, expletive)
x = '{}, {}!'.format(imperative, expletive)
x = 'name: %s; score: %d' % (name, n)
x = 'name: {}; score: {}'.format(name, n)
Join:
items = ['ni','hao'];
  employee_table = ''.join(items);

6、处理文件:

1、with open("hello.txt") as hello_file:
for line in hello_file:
print line
2、import contextlib

with contextlib.closing(urllib.urlopen("http://www.python.org/")) as front_page:
for line in front_page:
print line
 

7、变量等命名规范:

Python之父Guido推荐的规范

Type                  Public                      Internal
Modules             lower_with_under              _lower_with_under
Packages             lower_with_under             ---------
Classes             CapWords                  _CapWords
Exceptions           CapWords                 --------
Functions            lower_with_under()            _lower_with_under()
Global/Class Constants     CAPS_WITH_UNDER            _CAPS_WITH_UNDER
Global/Class Variables     lower_with_under            _lower_with_under
Instance Variables       lower_with_under             _lower_with_under (protected) or __lower_with_under (private)
Method Names           lower_with_under()            _lower_with_under() (protected) or __lower_with_under() (private)
Function/Method Parameters   lower_with_under
Local Variables         lower_with_under

python 规范的更多相关文章

  1. PEP8 python规范神器

    如需转载,请注明出处:小婷儿的博客:https://www.cnblogs.com/xxtalhr/p/10645992.html 一.Jupyter notebook 篇 Jupyter noteb ...

  2. Google实践中总结的Python规范,get了吗?

    好的代码风格,给人舒服的感觉,今天介绍一下谷歌的Python风格规范 1 分号 不要在行尾加分号, 也不要用分号将两条命令放在同一行. 2 行长度 每行不超过80个字符:不要使用反斜杠连接行.Pyth ...

  3. Python规范:提高可读性

    PEP 8 规范 PEP 是 Python Enhancement Proposal 的缩写,翻译过来叫"Python 增强规范". 缩进规范 PEP 8 规范告诉我们,请选择四个 ...

  4. Python规范:代码规范要注意

    主要有以下两种代码规范 <8 号 Python 增强规范>(Python Enhacement Proposal #8),以下简称 PEP8: <Google Python 风格规范 ...

  5. 基础python规范

    一.注释     合理的代码注释应该占源代码的 1/3 左右,Python 语言允许在任何地方插入空字符或注释,但不能插入到标识符和字符串中间.     在 Python 中,通常包括 3 种类型的注 ...

  6. Python规范:用用assert

    什么是assert assert的语法: assert_stmt ::= "assert" expression ["," expression] 例: ass ...

  7. python 规范篇 如何合理使用 assert

    assert 的合理使用,可以增加代码的健壮度,同时也方便了程序出错时开发人员的定位排查. 什么是 assert? Python 的 assert 语句,可以说是一个 debug 的好工具,主要用于测 ...

  8. Python规范

    1.命名 Django文件命名 小写+下划线 类:驼峰 2.edit 执行环境 work direction 到当前项目目录 3.类要加注释 4.去数据库找数据时需要try捕获异常,防止数据库连接断掉 ...

  9. python多态和规范

    python规范(接口类) 接口类可以规范代码,但接口类本身是不实现的 class Payment: def pay(self,money): raise Notlmplemented class W ...

随机推荐

  1. 定位到行的快捷键iOS

    1. 文件 CMD + N: 新文件CMD + SHIFT + N: 新项目CMD + O: 打开CMD + S: 保存CMD + SHIFT + S: 另存为CMD + W: 关闭窗口CMD + S ...

  2. 阿里云 putty链接服务器出现 server refused our key

    阿里云 putty链接服务器出现 server refused our key 创建了密钥对绑定实例,puttygen生成ppk,putty配置参数,连接,一步一步来的,结果出现 server ref ...

  3. 12.利用kakatips对网站数据信息监控

    网站信息监控 kakatips软件 百度云链接:https://pan.baidu.com/s/1lNH8OGODbIvYeFTjz6kVEQ 密码:5qtz 这是我编辑好的具体详情如下: 有效标记需 ...

  4. Python学习笔记_week2_列表、元组、字典、字符串、文件、i编码

    一. 列表.元组 names=["A","B","C","D"] print(names) print(names[0] ...

  5. java 正则 贪婪匹配 匹配sql语句中的引号内容

    public class Demo { public static void main(String[] args) { String sql1 = "use test;select * f ...

  6. 2. 解决svn working copy locked问题

    解决办法: 产生这种情况大多是因为上次svn更新命令执行失败且被自动锁定了. 如果cleanup没有效果的话只好手动删除锁定文件. 就可以通过“运行”--“cmd”--cd 到svn项目的根目录下,然 ...

  7. opencv画出轮廓外接矩形

    Mat cannyImage; /// Detect edges using canny Canny(src, cannyImage, , , ); vector<vector<Point ...

  8. JS 原型链 prototypt 和隐式原型 _proto_

    prototype(原型) :  对象的一个属性,此属性使您有能力向对象添加属性和方法,当访问对象不存在属性是会自动到 prototype 中找 _proto_(隐式原型): 此对象构造函数(类)的原 ...

  9. Model操作补充

    参考: http://www.cnblogs.com/wupeiqi/articles/6216618.html

  10. 微信、陌陌等著名IM软件设计架构详解(转)

    对微信.陌陌等进行了分析,发出来分享一下(时间有些久了) 电量:对于移动设备最大的瓶颈就是电量了.因为用户不可能随时携带电源,充电宝.所以必须考虑到电量问题.那就要检查我们工程是不是有后台运行,心跳包 ...