Python and Keyword
The Python and keyword is a logical operator which returns true when both of its operands are true, otherwise it returns false.
Syntax
(expression_1 and expression_2) (operand_1 and operand_2)
Example:
In the example below, and keyword is used to combine multiple conditions to execute a block of code only when all of the conditions are true.
x = 10 if (x > 5 and x < 15): print ('yes, x is in the range of 5 to 15.') else: print ('No, x is not in the range of 5 to 15.')
The output of the above code will be:
yes, x is in the range of 5 to 15.
Example:
In the example below, and keyword is used to combine multiple conditions and returns True only when all of the conditions are true.
x = 50 print (x > 5 and x < 15)
The output of the above code will be:
False
❮ Python Keywords