zoukankan      html  css  js  c++  java
  • python编码规范(二)——空行,换行,缩进

    python编码规范(二)——空行,换行,缩进

    1.空行

    • 空一行:用于类成员函数之间,或者用于区分不同逻辑块
    • 空两行:类与类,类与函数,函数与函数之间
    class Test(object):
    """Test class,提供通用的方法"""
      def __init__(self):
      """Test的构造器:"""
        pass
    
      def function1(self):
        pass
    
      def function2(self):
        pass
    
    def function3():   pass

    2.换行

    非集合元素

    • 反斜杠
    with open('test.txt','w') as file_1, 
         open("test2.txt", 'w') as file_2:
       file_2.write(file_1.read())
    • 字符串
    query_str = ('my name'
                 'is'
                 ' %s') % "Tom"
    print query_str
    • 二元运算符
    income = (gross_wages
              + taxable_interest
              + (dividends - qualified_dividends)
              - ira_deduction
              - student_loan_interest)

    3.缩进

    集合元素

    • 没有子模块: 一层缩进 
    my_list = [
      1, 2, 3,
      4, 5, 6,
      ]
    
    result
    = some_function_that_takes_arguments(   'a', 'b', 'c',   'd', 'e', 'f',   )
    • 有子模块: 两层缩进
    #if and
    if (this_is_one_thing
        and that_is_another_thing):
      do_something()
    # function
    def long_function_name(
        var_one, var_two,
        var_three,var_four):
      print(var_one)
    小丑竟是我自己
  • 相关阅读:
    mq概念
    Mac Xampp 安装redis 及 安装php-redis扩展
    rabbitmq死信队列(延迟队列)demo
    rabbitmq生产与消费测试
    RabbitMQ各方法详解
    Mac git old mode 100644 new mode 100755 mac目录权限问题
    mac安装redis
    msql创建用户并授权
    mac apache php 访问失败
    Kubernetes入门学习--在Ubuntu16.0.4安装配置Minikube
  • 原文地址:https://www.cnblogs.com/lspbk/p/14341185.html
Copyright © 2011-2022 走看看