程序员技术栈我爱编程

python编码规范(三)--空行,换行,缩进

2018-08-14  本文已影响6人  Godric_wsw

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)
上一篇下一篇

猜你喜欢

热点阅读