Date:

Share:

Stop Using “or” to Check Multiple Conditions in Python | by Görkem Arslan | Dec, 2021

Related Articles

Compare execution times

in [] - list
in () - tuple
in - set
or
0.0018657920008990914
0.0018152919947169721
0.00212829202064313
0.0020830420253332704
print(timeit.timeit('method = "GET"; method in ["GET", "HEAD", "OPTIONS"]', globals=globals(), number=100000))
0.004029749979963526
0.0039225000073201954
0.0028425419877748936
0.008492207998642698

Compare memory uses

120
64
216

Source

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Popular Articles