一行 if in Python 代码风格

One Line if in Python Code Style

正在寻找这样的东西:

if exits: sys.exit(msg)
if not result: print(msg)
if result: return msg

如何应用Python代码风格?

您只需添加缩进:

if exits: 
    sys.exit(msg)
if not result: 
    print(msg)
if result: 
    return msg

与大多数其他语言不同,Python 对缩进很敏感。

如果是这样,你可以使用一行:

import sys
sys.exit(msg) if exits else (msg if result else  sys.stdout.write(msg))