Sunday, May 26, 2019 17:04

Comparison operators

Another kind of operators we have enumerated are the comparison operators. As their name suggest, comparison operators are used to compare operands. There are 6 comparison operators:

All of the above operators return a Boolean value (true or false). Here is an example of using comparison operators:

The output of the above code snipet is

comparison operators

In the above example, we declared two integer variables, x and y and we assigned them the values of 9 and 3. On the next line, we used the comparison operator “greater than” to compare if x is greater than y, which output True, because, indeed, 9 is greater than 3.



Tags: ,

Leave a Reply