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

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

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

  1. ONE : Use 4-space indentation, and no tabs.--用4个空格键进行代码缩进,不要使用tab键.
  2.  
  3. 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.
  1. TWO : Wrap lines so that they dont exceed 79 characters.-- 每一行代码不要超过79字符.
  2.  
  3. This helps users with small displays and makes it possible to have several code files side-by-side on larger displays.
  1. THREE Use blank lines to separate functions and classes, and larger blocks of code inside functions. -- 在函数或者类中使用空白行
  1. FOUR : When possible, put comments on a line of their own.--添加注释,这个可以帮助你自己和他人阅读代码
  1. FIVE Use spaces around operators and after commas, but not directly inside bracketing constructs: a = f(1, 2) + g(3, 4).--在编写代码的过程中,注意使用空格,这样使得你的代码看上去清晰,美观
  1. 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 '这样的方式命名方法或者函数
  1. SEVEN : Dont use fancy encodings if your code is meant to be used in international environments. Pythons default, UTF-8, or even plain ASCII work best in any case. -- 统一使用UTF-8的编码方式进行编码
  1. EIGHT : Likewise, dont 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代码风格(coding style)的更多相关文章

  1. python开发_python关键字

    python3.3.2中的关键字如下: The following identifiers are used as reserved words, or keywords of the languag ...

  2. python的PEP8 代码风格指南

    PEP8 代码风格指南 这篇文章原文实际上来自于这里:https://www.python.org/dev/peps/pep-0008/ 知识点 代码排版 字符串引号 表达式和语句中的空格 注释 版本 ...

  3. python开发_python操作mysql数据库

    如果你还没有准备好开发环境,你不妨花上一小点时间去看看:python开发_mysqldb安装 本篇blog是有关python操作mysql数据的相关内容. 我做了一个demo: 先看运行效果: mys ...

  4. python开发_python概述

    Python(KK 英语发音:/ˈpaɪθən/,是一种面向对象.直译式计算机程序设计语言, 由Guido van Rossum于1989年底发明,第一个公开发行版发行于1991年. Python语法 ...

  5. python开发_python中的module

    在python中,我们可以把一些功能模块化,就有一点类似于java中,把一些功能相关或者相同的代码放到一起,这样我们需要用的时候,就可以直接调用了 这样做的好处: 1,只要写好了一个功能模块,就可以在 ...

  6. python开发_python中的变量:全局变量和局部变量

    如果你在为python中的变量:全局变量和局部变量头疼,我想这篇blog会给你帮助 运行效果: 代码部分: #Python中的变量:全局变量和局部变量 #在很多语言中,在声明全局变量的时候,都喜欢把全 ...

  7. python开发_python中字符串string操作

    在python中,对于字符串string的操作,我们有必要了解一下,这样在我们的以后的开发中会给我们带来很多方便 下面是我学习的笔记: #python-string #python中的字符串用单引号' ...

  8. jquery开发之代码风格

    1,链式操作风格. (1) 对于同一个对象不超过三个操作的.可直接写成一行.代码例如以下: $("li").show().unbind("click"); (2 ...

  9. python开发_python中str.format()

    格式化一个字符串的输出结果,我们在很多地方都可以看到,如:c/c++中都有见过 下面看看python中的字符串格式函数str.format(): 1 #使用str.format()函数 2 3 #使用 ...

随机推荐

  1. 多线程中的超时, 如Socket超时

    ; ,,, ->$port { print "-->$port\r"; #say "\r"; await Promise.anyof( Promis ...

  2. numpy 简介

    .caret, .dropup > .btn > .caret { border-top-color: #000 !important; } .label { border: 1px so ...

  3. 多个id或class属性相同的元素绑定事件

    <td class="tools"><a href="javascript:void(0);" status="0" na ...

  4. 2017 ACM - ICPC Asia Ho Chi Minh City Regional Contest

    2017 ACM - ICPC Asia Ho Chi Minh City Regional Contest A - Arranging Wine 题目描述:有\(R\)个红箱和\(W\)个白箱,将这 ...

  5. Python 类的名称空间和组合

    一.Python类的名称空间 class Student(object): School = '北京大学' def __init__(self): pass stu1 = Student() stu1 ...

  6. 工作当中遇到的ssh错误

    [root@1bcc1d3f9666 externalscripts]# /usr/sbin/sshd Could not load host key: /etc/ssh/ssh_host_rsa_k ...

  7. systemd基础

    systemd 起源 systemd这一名字源于Unix中的一个惯例:在Unix中常以“d”作为系统守护进程(英语:daemon,亦称后台进程)的后缀标识.除此以外,systemd亦是借代英文术语D体 ...

  8. 【原创】Scrapyd 的 .net 客户端

    最近项目需要部署Scrapy爬虫,采用最简单的Scrapyd服务进行部署,基于.net core 进行了客户端的封装. 1)Scrapyd API文档:http://scrapyd.readthedo ...

  9. mean(bootstrap,angular,express,node,mongodb)通用后台框架

    学习node,我这个毫无美感的程序员在bootstrap与node的感染下,向着“全栈工程师”迈进,呵呵! 最终选择如题的技术方案,这些东东都算比较新的,网上的资料比较少,参考了不少github程序及 ...

  10. Adsafe 导致win10 中窗口错位

    域账号使用,出现上述情况,干掉后一切恢复正常... 还好家里的本地管理员账号使用一切正常,不然又被广告占领了