相关疑难解决方法(0)

打破长if语句的推荐方法是什么?(二元运算符后的 W504 换行符)

目前推荐的用“and”和“or”运算符打破一长串if语句的推荐方法是什么?

第一个选项

使用下面的样式(来自 PEP8)和 flake8 我收到警告:二元运算符后的 W504 换行符:

if (this_is_one_thing and
    that_is_another_thing):
    do_something()
Run Code Online (Sandbox Code Playgroud)

第二个选项

if (this_is_one_thing
    and that_is_another_thing):
    do_something()
Run Code Online (Sandbox Code Playgroud)

现在我在二元运算符之前收到警告 W503 换行符。第二个似乎符合PEP8 的这个建议

我试图找到答案,但我仍然不确定。我认为也许使用第二个选项并禁用 W503 警告将是处理此问题的一种方法?

python pep8 python-3.x flake8

25
推荐指数
2
解决办法
1万
查看次数

标签 统计

flake8 ×1

pep8 ×1

python ×1

python-3.x ×1