Python's equivalent of && (logical-and) in an if-statement
In Python, the logical "and" operator is represented by the and
keyword. Here is an example of how you might use it in an if-statement:
Watch a video course
Python - The Practical Guide
It can also be used in a ternary expression like this:
x = 1
y = 2
result = "Both are positive" if x > 0 and y > 0 else "One of them is not positive"
print(result)
Please note that and
operator is bit different than &
which is bitwise operator, and has different behaviour.