For example:
x = [1, 2, 3]
y = [4, 5, 6]
print(x and y)
When I run this, the result is [4, 5, 6]. Can someone explain what is happening?
For example:
x = [1, 2, 3]
y = [4, 5, 6]
print(x and y)
When I run this, the result is [4, 5, 6]. Can someone explain what is happening?
From the Python documentation (https://docs.python.org/3/reference/expressions.html#and):
The expression
x and y
first evaluates x; if x is false, its value is returned; otherwise, y is evaluated and the resulting value is returned.
So it will be evaluating x
, which is not false, then returning y
.