Friday, May 20, 2022 19:37

Table of contents >> Introduction > Comparison operators

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.

The concepts explained in this lesson are also shown visually as part of the following video:

Tags: ,

Leave a Reply



Follow the white rabbit