AND OR and NOT
AND OR and NOT Keywords in Python
A logical operator is a symbol or word used to link two or more expressions in such a way that the value of the generated compound expression depends solely on that of the original expression and the operator’s meaning. Some of the familiar logical operators are AND, OR and NOT.
All these logical operator returns boolean value
AND Keyword
It is one of the logical operator used to combine conditional statements.
It returns True only if both of the conditions are True else it returns False.
Syntax –
condition1 and condition2
If both conditions in given code is true then if statement executed otherwise else statement executed.
Example
a=10 b=5 if(a>2 and b==5): print("AND works fine") else: print("It's not working")
Output: AND works fine
OR Keyword
It is one of the logical operator used to combine conditional statements.
It returns True if any of the conditions are True else it returns False.
Syntax –
condition1 or condition2
Here a >2 is True but b!=5 is False
Example
a=10 b=5 if(a>2 or b!=5): print("Hello world!") else: print("It's not working")
Output: Hello world!
NOT Keyword
It returns True if input is False and returns False if input is True.
NOT acts like as converter.
Syntax –
not var1
Example
if(not True): print("I am here") else: print("I am not there")
Output: I am not there
Prime Course Trailer
Related Banners
Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription
Get over 200+ course One Subscription
Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others
Login/Signup to comment