I can't understand these code | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

I can't understand these code

code1 : a = [1] func = (lambda x: x.append("a")) and (lambda x: x.append("b")) func(a) print(a) out put is [1,"b"] code2: a = [1] func = (lambda x: x.append("a")) or (lambda x: x.append("b")) func(a) print(a) out put is [1,"a"] I don't understand. why the out put of code 1 is not [1,"a","b"] anyone can tell me how the code run? Thanks.

13th Mar 2019, 6:06 PM
Hanyong He
Hanyong He - avatar
1 Answer
+ 4
Because and operator works in this way, when the first operand is true, it returns the second operand.
14th Mar 2019, 4:35 AM
Gordon
Gordon - avatar