Page 94 - Information_Practice_Fliipbook_Class11
P. 94
4.4.2 Relational Operators
A relational operator is used to compare the values of operands on either side. The result of applying a relational
operator is either True or False. Table 4.2 describes the relational operators.
Table 4.2: Relational Operators
(Assume that the variables a, b, c have values 10, 5, and -2, respectively)
Operator Operation Explanation Examples
== equal to Yields True if the operands on either >>> c == -2
side are equal and False otherwise. True
>>> a == b
False
!= not equal to Returns True if operands on the two >>> a != b
sides of the operator are not equal, True
False otherwise.
>>> c != -2
False
> greater than Yields True if the value on the LHS of >>> a > b
the operator is greater than that on its True
RHS, and False otherwise.
>>> c > 0
False
< less than Yields True if the value on the LHS >>> c < b
of the operator is less than that on True
the RHS of the operator, and False >>> b < 0
otherwise.
False
>= greater than or Yields True if the value on the LHS of >>> c >= -2
equal to the operator is greater than or equal to True
the value on the RHS of the operator,
>>> b >= a
and False otherwise.
False
<= less than or Yields True if the value on the LHS of >>> c <= -2
equal to the operator is less than or equal to True
the value on the RHS of the operator,
>>> b <= c
otherwise False.
False
4.4.3 Assignment Operators
Assignment operators are used to assign the value of the operand on the right-hand side of the operator to the
operand on the left-hand side of the operator. (see Table 4.3: Assignment Operators)
(Assume the value of a, b, and c to be 10, 5, an -2, respectively for computations in the table)
80 Touchpad Informatics Practices-XI

