摘自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

最新文章

  1. iOS 启动图那些坑
  2. 用C语言制作爱心
  3. SQL注入测试平台 SQLol -5.DELETE注入测试
  4. Oracle translate 函数的用法, 以及和replace的区别
  5. [改善Java代码] 避免instanceof非预期结果
  6. 使用Ubuntu 新建vpn过程
  7. Free Sql Server SMSS format Plugin
  8. mysql5 乱码问题解决方案
  9. jquery的选项卡事件
  10. Hadoop伪分布式模式部署
  11. springMVC+Java验证码完善注册功能
  12. jenkins - ssh Server Groups Center
  13. json的那些事
  14. 如何减小ios安装包大小
  15. Docker命令查询
  16. Multiple dex files define Lcom/google/gson/internal/Streams$AppendableWriter$CurrentWrite;
  17. Java 集合类框架
  18. Coprime Sequence (HDU 6025)前缀和与后缀和的应用
  19. PICE(5):MongoDBStreaming - gRPC -MGO Service
  20. hibernate的三种状态和缓存

热门文章

  1. c# 后台AJAX
  2. webDAV
  3. Xshell 本地上传、远程下载文件
  4. 《算法》第四章部分程序 part 11
  5. excel导入导出的两种方式:csv和XLS
  6. zookeeper(4)--zookeeper分布式锁原理
  7. 使用mondorescue将本机linux centos 7服务器制作成光盘
  8. journalctl
  9. Android自定义View学习(三)
  10. JAVA SpringBoot 项目打包(JAR),在打包成 docker 镜像的基本方法