Can anyone explain, What exactly the exp1 and exp2 are doing? Kindly separate each case so it can understandable.
a, b, c, d, e, f = 0, 5, 12, 0, 15, 15
exp1 = a <= b < c > d is not e is f
exp2 = a is d > f is not c
print(exp1)
print(exp2)
Can anyone explain, What exactly the exp1 and exp2 are doing? Kindly separate each case so it can understandable.
a, b, c, d, e, f = 0, 5, 12, 0, 15, 15
exp1 = a <= b < c > d is not e is f
exp2 = a is d > f is not c
print(exp1)
print(exp2)
exp1 = a <= b < c > d is not e is f
is evaluated as a<=b and b<c and c>d and d is not e and e is f
.
Byte-code for both expressions is the same (dis module reference).
In [8]: import dis
In [9]: dis.dis('a <= b < c > d is not e is f')
1 0 LOAD_NAME 0 (a)
2 LOAD_NAME 1 (b)
4 DUP_TOP
6 ROT_THREE
8 COMPARE_OP 1 (<=)
10 JUMP_IF_FALSE_OR_POP 48
12 LOAD_NAME 2 (c)
14 DUP_TOP
16 ROT_THREE
18 COMPARE_OP 0 (<)
20 JUMP_IF_FALSE_OR_POP 48
22 LOAD_NAME 3 (d)
24 DUP_TOP
26 ROT_THREE
28 COMPARE_OP 4 (>)
30 JUMP_IF_FALSE_OR_POP 48
32 LOAD_NAME 4 (e)
34 DUP_TOP
36 ROT_THREE
38 COMPARE_OP 9 (is not)
40 JUMP_IF_FALSE_OR_POP 48
42 LOAD_NAME 5 (f)
44 COMPARE_OP 8 (is)
46 RETURN_VALUE
>> 48 ROT_TWO
50 POP_TOP
52 RETURN_VALUE
In [10]: dis.dis('a<=b and b<c and c>d and d is not e and e is f')
1 0 LOAD_NAME 0 (a)
2 LOAD_NAME 1 (b)
4 COMPARE_OP 1 (<=)
6 JUMP_IF_FALSE_OR_POP 38
8 LOAD_NAME 1 (b)
10 LOAD_NAME 2 (c)
12 COMPARE_OP 0 (<)
14 JUMP_IF_FALSE_OR_POP 38
16 LOAD_NAME 2 (c)
18 LOAD_NAME 3 (d)
20 COMPARE_OP 4 (>)
22 JUMP_IF_FALSE_OR_POP 38
24 LOAD_NAME 3 (d)
26 LOAD_NAME 4 (e)
28 COMPARE_OP 9 (is not)
30 JUMP_IF_FALSE_OR_POP 38
32 LOAD_NAME 4 (e)
34 LOAD_NAME 5 (f)
36 COMPARE_OP 8 (is)
>> 38 RETURN_VALUE
exp2 = a is d > f is not c
is evaluated as a is d and d>f and f is not c
. They both would produce the same byte-code.