Python doubt on "extend" "boolean operator"

Python doubt on "extend" "boolean operator"
0

#1

a = [12,4,56,43,66,2,1.5]
a.append(a[3] and a[5])
print(a)

[12, 4, 56, 43, 66, 2, 1.5, 2]
----------------------------------However------------------------

a = [12,4,56,43,66,2,1.5]
a.append(a[3] or a[5])
print(a)

[12, 4, 56, 43, 66, 2, 1.5, 43 ]

Why and/ or respectively gives these results?


#2

I believe which ever value is the last in the expression which causes the expression to evaluate to true, then it gets appended. In the first example, you used the and operator, so both have to be true for the entire expression to be true. The last value in the condition (a[5]) gets appended. I

In the second example, the or operator only needs one true value to make the entire expression true, so it stops at a[3] and the a[3] gets appended.