缩进

Tip

用4个空格来缩进代码

绝对不要用tab, 也不要tab和空格混用. 对于行连接的情况, 你应该要么垂直对齐换行的元素(见 行长度 部分的示例), 或者使用4空格的悬挂式缩进(这时第一行不应该有参数):

  1. Yes: # Aligned with opening delimiter
  2. foo = long_function_name(var_one, var_two,
  3. var_three, var_four)
  4.  
  5. # Aligned with opening delimiter in a dictionary
  6. foo = {
  7. long_dictionary_key: value1 +
  8. value2,
  9. ...
  10. }
  11.  
  12. # 4-space hanging indent; nothing on first line
  13. foo = long_function_name(
  14. var_one, var_two, var_three,
  15. var_four)
  16.  
  17. # 4-space hanging indent in a dictionary
  18. foo = {
  19. long_dictionary_key:
  20. long_dictionary_value,
  21. ...
  22. }
  1. No: # Stuff on first line forbidden
  2. foo = long_function_name(var_one, var_two,
  3. var_three, var_four)
  4.  
  5. # 2-space hanging indent forbidden
  6. foo = long_function_name(
  7. var_one, var_two, var_three,
  8. var_four)
  9.  
  10. # No hanging indent in a dictionary
  11. foo = {
  12. long_dictionary_key:
  13. long_dictionary_value,
  14. ...
  15. }