 
                        比如五个条件A/B/C/D/E,会有32种情况
if A and B and C and D and E:
    do_one()
elif A and B and C and D and not E:
    do_two()
elif A and B and C and not D and E:
    do_three()
...
...
...
else:
    do_32()有更简洁的写法吗?
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
You could use a dictionary:
来自:http://stackoverflow.com/a/60211
如果需要调用函数,你可以这样
很显然,输出为
建议每个条件作为一个二进制位或者10进制为,只需要无嵌套的有限个if,然后根据你的取值到一个dict中取得该值对应的函数, 也就是自己根据状态码做一层路由。
感觉可以考虑用一下装饰器。
通用的逻辑做wrapper, 然后对于特殊情况hardcode。
推荐按位进行计算