Python Operator

 Python Operator

2. Comparison operator:

Define:

 The operator or symbol that is used to compare two or more values.

  • It returns the results as true or false.
  • It is used for condition and decision-making.
  • The symbols are : = =><> =,  < =,  and  !=.

Some examples are as follows:

a = 12

b = 10

  • ==

If we write to compare the above two variables as a==b, it will return false because 12 and 10 are not equal.

  • > 

This operator is 'is greater'. This operator checks that the first value is greater than the second. As a > b, it will return true because 12 is greater than 10.

  • <

This operator is 'is less than'. This operator checks that the first value is less than the second. As a < b, it will return true because 12 is greater than 10.

  • > =
This operator is the combination of two symbols > and =. This operation is solved in two steps. If one condition is true, it will return true as a whole. Otherwise false.

a  > =  b it solves as:

a > b    |  12 > 10    (true)

a = b  |  12 = 10    (false)

So this condition is true.

  • < =

This operator is also the combination of two symbols < and =, less than, and equal to This operation is also solved in two steps. If any one condition is true, it will return true. Otherwise false.

a  < =  b it solves as:

a < b   |  12 < 10       (false)

a = b  |   12 = 10       (false)

So this condition is false.

  • !=

This operator also consists of two symbols. These symbols are solved as single. It checks the first value is not equal to the second value.

a != b, the result is true, because 12 is not equal to 10.

Comments

Popular posts from this blog

Programming in Python

Programming lists in Python

Python Operator

Practice of Operators

Bit wise operators