【发布时间】:2020-08-29 10:00:09
【问题描述】:
我能知道这里有什么不同吗? 假设 A 是二维数组,B 是 int
if(A[i][j] == 2):
res += B == 0
和
if(B == 0 and A[i][j] == 2):
res += 1
【问题讨论】:
-
逻辑上?没有。但是第二个更清晰,效率更高(如果 B 为零,您甚至不检查数组)。
-
发布问题时请添加完整代码。
标签: python-3.x list if-statement operators