![]() |
Python OR Operator takes at least two boolean expressions and returns True if any one of the expressions is True. If all the expressions are False then it returns False. Flowchart of Python OR Operator![]() Truth Table for Python OR Operator
Using Python OR Operator with Boolean ExpressionPython OR operator returns True in any one of the boolean expressions passed is True. Example: Or Operator with Boolean Expression
Output bool1: False bool2: True OR operator: True Using Python OR Operator in ifWe can use the OR operator in the if statement. We can use it in the case where we want to execute the if block if any one of the conditions becomes if True. Example: Or Operator with if statement
Output a either a multiple of 3 or 5 a is not a multple of 3 or 5 a either a multiple of 3 or 5 Python OR Operator – Short CircuitThe Python Or operator always evaluates the expression until it finds a True and as soon it Found a True then the rest of the expression is not checked. Consider the below example for better understanding. Example: Short Circuit in Python OR Operator
Output Inside True Case 1 True Inside True Case 2 True Inside False Inside False Case 3 False Inside False Inside True Case 4 True From the above example, we can see that the short circuit or lazy evaluation is followed. In case1 and case2, the second expression is not evaluated because the first expression returns True, whereas, in case3 and case4 the second expression is evaluated as the first expression does not returns True. |
Reffered: https://www.geeksforgeeks.org
Python |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 10 |