Python 常见的代码规范问题整理

Python 常见的代码规范问题整理

空一行: 用于 【类成员函数之间】 ,或者用于区分不同逻辑块
空两行: 类与类,类与函数,函数与函数之间

1. 函数或代码段终止处出现了多余的空格
W291 trailing whitespace
2. 空行中包含空格
W293 blank line contains whitespace
3. 类 或 函数结尾 2个空行
E305 expected 2 blank lines after class or function definition
4. 空两行:类与类,类与函数,函数与函数之间
E302 expected 2 blank lines
5. 空一行:用于【类成员函数之间】,或者用于区分不同逻辑块
6. 单行不得超过 79 个字符
E501 line too long (89 > 79 characters)
换行

非集合元素

  • 反斜杠
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)
Python代码规范 PDF 合集下载

你可能感兴趣的:(Python,Python,代码规范,PEP,8)