filmov
tv
Python 3 Basics: Logical Operators

Показать описание
Hello guys, let's check out logical operators in python. With logical operators, we can implement two or more conditions on a single line. This is really helpful if we need to use multiple conditions or a single condition (True) from a set of conditions to validate the input.
We have 3 logical operators in python:
and, or, not.
Each of them has a specific function :
AND:- if (condition1 and condition2) { execute me }
the execute me code block will be executed only if condition1 is True and condtion2 is True as well;
True and True:- True
OR:- if (condition1 or condition2) { execute me }
the execute me code block will be executed if condition1 is True or condtion2 is True or both are True. The code block will only be skipped if both the conditions are False.
True or False:- True
False or True:- True
True or True:- True
False or False:- False
NOT:- if not condition { execute me }
execute me code block will be executed if the condition is False. This is because not keyword toggles the condition output. In simple words 'not' keyword will convert True --} False and False --} True.
True:- False
False:- True
Here are some useful links:
We have 3 logical operators in python:
and, or, not.
Each of them has a specific function :
AND:- if (condition1 and condition2) { execute me }
the execute me code block will be executed only if condition1 is True and condtion2 is True as well;
True and True:- True
OR:- if (condition1 or condition2) { execute me }
the execute me code block will be executed if condition1 is True or condtion2 is True or both are True. The code block will only be skipped if both the conditions are False.
True or False:- True
False or True:- True
True or True:- True
False or False:- False
NOT:- if not condition { execute me }
execute me code block will be executed if the condition is False. This is because not keyword toggles the condition output. In simple words 'not' keyword will convert True --} False and False --} True.
True:- False
False:- True
Here are some useful links: