小编Lar*_*sus的帖子

缩短一条if语句,其语句被反转

我有以下情况:

string = "abc"
if (string[1] == "b" and string[2] == "c") or (string[1] == "c" and string[2] == "b"):
    print("ERROR")
Run Code Online (Sandbox Code Playgroud)

是否有解决方案以pythonic方式缩短此时间?我看到这(string[1] == "b" and string[2] == "c")是的相反陈述(string[1] == "c" and string[2] == "b")。也许我可以使用?

python algorithm if-statement code-readability

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