是否允许将 if 语句写成一行?

Is it allowed to write if-statements as one-liner?

编写关于换行符的 if 语句的推荐方法是什么?

显然有两种可能。第一个来自 Google's Python Style Guide,第二个是换行的变体。

if foo: bar(foo)

对比

if foo:
    bar(foo)

根据现有指南或PEPs(避免基于意见的讨论)应该首选哪个变体?

来自PEP 8

Compound statements (multiple statements on the same line) are generally discouraged.

[...]

Rather not:

if foo == 'blah': do_blah_thing()

do_one(); do_two(); do_three()