Boolean Operators in Python
Boolean Expression(Operator) in Python
Boolean Expression helps in attesting True OR False given a comparison.Illustration
> 4 == 4
True
> 6 == 2
False
True & False aren't strings. They belong to type bool.
We can validate the type by using the following illustration law.> type ( True)
type'bool'
> type( False)
type'bool'
Comparison Drivers in Python
Comparison Drivers are available for the purpose of comparison. We validate equal to, lesser than or lower than and so on. To support these kind of comparisons, we use comparison drivers. For illustration, the before used' == 'is one zilches the comparison driver.
The following are list of comparison drivers
a == b# it represents a equal to b
a> b# it represents a lesser than b
a< b# it represents a lower than b
a! = b# it represents a not equal to b
a> = b# it represents a lesser than or equal to b
Logical Drivers denote the relationship between two Boolean expressions in python. Logical drivers are also appertained to as python Boolean drivers. Two or further conditions can be combined using Boolean drivers. Conditions are generally appertained to as a Boolean expression in python. The syntax for using Boolean driver is
Boolean_Expression1Boolean_operatorBoolean_Expression 2
Boolean_Expression1Boolean_operatorBoolean_Expression 2
Following are the logical drivers used in python
Let’s have a brief look at the Boolean drivers
The'and'Operator
'and'is veritably important and primarily used among all three python Boolean drivers.'and' checks that all the conditions in the Boolean expressions are fulfilling. For illustration, the table given below shows different conditions in which the outgrowth/ result is decided.
The easy trick to remember this table – Only when all the Boolean expressions are true, also the final result is true; else the result is false.
See the following law for a better understanding
a = 10
b = 5
c = 10
d = 5
print( a> b and c> d)# both conditions are true
print ( announcement)# 1st condition is true second is false.
InsideAIML is the platform where you can learn AI & ML Deeply and get certified too.
Comments
Post a Comment