def is_even(a: int) -> bool:
"""确定数a是否是偶数."""
if a % 2 == 0:
print('偶数!')
return True
print('奇数!')
return False
# 参数比后续部份多一层缩进
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,
}