rag*_*ner 2 python if-statement python-3.x
这两个条件检查是否相同?我想不出如何检查它们是否相同
l1 = []
l2 = []
if not l1 and not l2:
print ('y')
if not (l1 and l2):
print ('y')
Run Code Online (Sandbox Code Playgroud)
感谢所有回复的人,我已经做了一些基本的时机,看看哪个更快
import time
l1 = []
l2 = []
st = time.time()
for i in range(100000000):
if not l1 and not l2:
pass
end = time.time()
print ('if not l1 and not l2: '+str(end-st))
st = time.time()
for i in range(100000000):
if not (l1 or l2):
pass
end = time.time()
print ('if not (l1 or l2): '+str(end-st))
Run Code Online (Sandbox Code Playgroud)
打印:
if not l1 and not l2: 8.533874750137329
if not (l1 or l2): 7.91820216178894
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
100 次 |
| 最近记录: |