Booleans

Booleans

In programming, you often need to know if an expression is True or False.

You can evaluate any expression in Python, and get one of two answers, True or False.

When you compare two values, the expression is evaluated and Python returns the Boolean answer:

-------------------------------------------------------

code:-

print(5 > 3)

print(10 < 5)

print(100 == 99)

output:-

True

False

False

---------------------------------------------------------

You can also store boolean values in variables.

-------------------------------------------------------

code:-

x = 10 > 3

print(x)

output:-

True

---------------------------------------------------------

To get a boolean value comparison operators are used.

There are different comparison operators in python.

Operator                                            Name                                                          Example

==                                                          Equal                                                                  x == y

!=                                                        Not equal                                                           x != y

>                                                      Greater than                                                                 x > y

<                                                        Less than                                                            x < y

>=                                                 Greater than or equal to                                            x >= y

<=                                                 Less than or equal to                                                  x <= y



Comments

Post a Comment

Popular posts from this blog

Comments

#1- Let's Learn Python In the least possible time

#9 - String Concatenation