Python | logical operators





Python  | logical operators

 

Python Logical Operators are used to perform operations  on values and variables. that was special symbols that carry out arithmetic and logical operations

A logical operator is a symbol or word used to connect two or more expressions 


There are three logical operators 

1 ) AND

2) OR

3) NOT



1) AND  Operator

It is used for to combine a statements , in this , if both condition are true then will execute statement

 

Example

x = 95

        y = 97

        z = 92


        if x < y and x > z :

print("the both condition are true")


Output

    the both condition are true


Note : If both condition is true then return true , Otherwise false 


If any one condition is false then return false .

Example

x = 95

        y = 97

        z = 92


        if x < y and x < z :

print("the both condition are true")

        else :

        print("any one condition is false")


Output

    any one condition is false




2) OR Operator

Its used for combine statements, in this if any one condition is true then will execute  statement


Example


x = 95

        y = 97

        z = 92


        if x > y or x > z :

print("any one condition is true")

Output

        any one condition is true


Note : If both conditions are false the return false. Otherwise return True

If both conditions are false the return false

Example

    x = 95

    y = 97

    z = 92


    if x > y or x < z :

print("any one condition is true")

    else:

    print("both conditions are false")


Output

    both conditions are false



3 ) NOT Operator

Not operator is work with single value . the boolean value is true then it Not Operator return false.

Example

    a = 10

    if not a:

print("Boolean value of a is True")

    else:

print("Not operator return False")


Output

    Not operator return False

Post a Comment (0)
Previous Post Next Post