+ 3

Python - Why is b [1,1,1]?

x = [0,0,0] y = [1,1,1] b = x and y print(b) print(not b)

22nd Sep 2019, 8:44 AM
Paolo De Nictolis
Paolo De Nictolis - avatar
2 ответов
+ 3
Lists are supposed to be true when not empty, so both x and y are considered true. Their contents don't matter. Because both x and y are not empty, x and y simply return the second list object only if x was empty would it be returned [] instead. Example x = [] y = [1,2,3] x and y -----> [] x = [1,2,3] y = [0,0,0] x and y -----> [0,0,0]
22nd Sep 2019, 9:02 AM
Phurinat Puekkham
Phurinat Puekkham - avatar
+ 2
0 equal false 1 equal true True and false is false 0 No false is true 1
22nd Sep 2019, 9:48 AM
guillem ardanuy
guillem ardanuy - avatar