>>> import dis >>> f1 = lambda: 10 + 20 # yes, decompiling we see the sum was precalculated... >>> dis.dis(f1) 1 0 LOAD_CONST 2 (30) 3 RETURN_VALUE # ...but still, the old constants were kept >>> f1.func_code.co_consts (10, 20, 30) # actually, all intermediate values are kept >>> f2 = lambda: 1 + 2 + 10 + 100 >>> f2.func_code.co_consts (1, 2, 10, 100, 3, 13, 113) # and even duplicated constants are generated >>> f3 = lambda: 7 * 1 >>> f3.func_code.co_consts (7, 1, 7) # the same applies for other types of constants >>> f4 = lambda: 'a' + 'b' + 'c' + 'd' + 'e' >>> f4.func_code.co_consts ('a', 'b', 'c', 'd', 'e', 'ab', 'abc', 'abcd', 'abcde') # this is probably related: named functions always have a None # constant, while lambda functions do not; this None is probably # a residue from named functions receiving an automatic "return None" # when they don't have an explicit return >>> def named(): return 1 >>> anonymous = lambda: 1 >>> dis.dis(named) 2 0 LOAD_CONST 1 (1) 3 RETURN_VALUE >>> named.func_code.co_consts (None, 1) >>> dis.dis(anonymous) 1 0 LOAD_CONST 0 (1) 3 RETURN_VALUE >>> anonymous.func_code.co_consts (1,)