Why is if True slower than if 1?
问题 Why is if True slower than if 1 in Python? Shouldn't if True be faster than if 1 ? I was trying to learn the timeit module. Starting with the basics, I tried these: >>> def test1(): ... if True: ... return 1 ... else: ... return 0 >>> print timeit("test1()", setup = "from __main__ import test1") 0.193144083023 >>> def test2(): ... if 1: ... return 1 ... else: ... return 0 >>> print timeit("test2()", setup = "from __main__ import test2") 0.162086009979 >>> def test3(): ... if True: ... return