Tutorial Python 7: Boolean Operators - Printable Version +- Red Security (https://redsecurity.info/cc) +-- Forum: Programming (https://redsecurity.info/cc/forumdisplay.php?fid=5) +--- Forum: Python (https://redsecurity.info/cc/forumdisplay.php?fid=9) +--- Thread: Tutorial Python 7: Boolean Operators (/showthread.php?tid=7888) |
Python 7: Boolean Operators - Covid-19 - 04-19-2022 Boolean logical operators: Boolean logical operators are used in decision making and control the flow of a program. There are three boolean functions in python i.e AND, OR, NOT. The resultant of these evaluates to true on the following condition. AND evaluates to true when both of the statement evaluates to true Keeps this table in your mind for ‘and’ operator Condition1 Condition2 Result True True True True False False False True False False False Flase Let’s code an example for ‘and’ to better understand. Code: Program: So in this program if any of these statements evaluates to false the program will print the else's statement. The statements inside ‘if’ will run only when both of these conditions are true. OR evaluates to true when one of the statements is true. Keep this table in your mind for 'or' operator. Condition1 Condition2 Result True True True True False False False True False False False Flase Let’s code an example for ‘and’ to better understand. Code: # Program to demonstrate ‘or’ NOT operator alters the resultant if it is true it makes it false and vice versa. If the condition is true the result is false and if the condition is false the result is true Let's write a code for not operator.. Program: Code: # Program to verify your age for adult sites Hope You understand each and every line take good care of your health. ("Allah Hafiz" and "Good Bye" Till the next post ) "Keep Learning and Keep exploring" |