越位规则

定义

```if foo
then do first thing
second thing
third thing
else do something_else
```
```if foo
then do first thing
second thing
third thing
else do something_else
```
```if foo
then do
first thing
second thing
third thing
else do
something_else
```
```if foo
then do
first thing
second thing
third thing
else do
something_else
```

1. ^ 组合起来的同类短语必须精确的对齐。
2. ^ 从在行首的符号`then`所属的短语的角度看，和从不在行首的`do`所属的短语的角度看，都是悬挂缩进。
3. ^ 从在行首的符号`then`所属的短语的角度看是悬挂缩进；从不在行首的`do`所属的短语的角度看，缩进区块相当于用括号包围起来的除外情况。

程式範例

```def is_even(a: int) -> bool:
"""确定数a是否是偶数."""
if a % 2 == 0:
print('偶数!')
return True
print('奇数!')
return False
```

Python中括号内多行代码会隐式的接合在一起，也有着相应的缩排规则：

```# 参数比后续部份多一层缩进
def long_function_name(
var_one, var_two, var_three,
var_four):
# 可选的圆括号内后续行多一层缩进，注意这里关键字在行首
if (this_is_first_thing
and that_is_second_thing):
do_something()
# 可选的圆括号内后续行不额外缩进，同类语言元素垂直对齐
elif (this_is_third_thing and
that_is_fourth_thing):
do_something_different()
# 悬挂缩进，参数比行首缩进一层
spam = long_function_name(
arg_one, arg_two,
arg_three, arg_four)
# 按开定界符垂直对齐
eggs = long_function_name(arg_one, arg_two,
arg_three, arg_four)
#可选的闭括号位置
my_list = [
1, 2, 3,
4, 5, 6,
]
# 可选的闭括号位置
my_set = {
1, 2, 3,
4, 5, 6,
}
```

參考資料

1. ^ Landin, P. J. The next 700 programming languages (PDF). Comm. ACM. March 1966, 9 (3): 157–166. doi:10.1145/365230.365257. Indentation, used to indicate program structure. A physical ISWIM can be defined in terms of an unspecified parameter: a subset of phrase categories, instances of which are restricted in layout by the following rule called "the offside rule." The southeast quadrant that just contains the phrase's first symbol must contain the entire phrase, except possibly for bracketed subsegments. This rule has three important features. It is based on vertical alignment, not character width, and hence is equally appropriate in handwritten, typeset or typed texts. Its use is not obligatory, and use of it can be mixed freely with more conventional alternatives like punctuation. Also, it is incorporated in ISWIM in a systematic way that admits of alternatives without changing other features of ISWIM and that can be applied to other languages.
2. ^
3. ^ Python FAQ on colons. [2012-04-30]. （原始内容存档于2012-02-07）.
4. ^
5. ^ The Haskell Report - Layout. [2012-04-30]. （原始内容存档于2012-03-31）.