+ 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)
2 Answers
+ 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]
+ 2
0 equal false
1 equal true
True and false is false 0
No false is true 1