缩进
Tip
用4个空格来缩进代码
绝对不要用tab, 也不要tab和空格混用. 对于行连接的情况, 你应该要么垂直对齐换行的元素(见 行长度 部分的示例), 或者使用4空格的悬挂式缩进(这时第一行不应该有参数):
- Yes: # Aligned with opening delimiter
- foo = long_function_name(var_one, var_two,
- var_three, var_four)
- # Aligned with opening delimiter in a dictionary
- foo = {
- long_dictionary_key: value1 +
- value2,
- ...
- }
- # 4-space hanging indent; nothing on first line
- foo = long_function_name(
- var_one, var_two, var_three,
- var_four)
- # 4-space hanging indent in a dictionary
- foo = {
- long_dictionary_key:
- long_dictionary_value,
- ...
- }
- No: # Stuff on first line forbidden
- foo = long_function_name(var_one, var_two,
- var_three, var_four)
- # 2-space hanging indent forbidden
- foo = long_function_name(
- var_one, var_two, var_three,
- var_four)
- # No hanging indent in a dictionary
- foo = {
- long_dictionary_key:
- long_dictionary_value,
- ...
- }