Page 29 - 2501_KVS_C-7
P. 29

Expression: An expression is a combination of operators and operands.
                 In an expression x = y + 9,

                 x, y, and 9 are operands, while = and + are operators.
                 Types  of Operators:  Python  allows  eight  types  of  operators.  In  this  chapter,  we  will

                 discuss two types of operators.

                 2.5.1 Arithmetic Operator
                 Arithmetic operator is used to apply basic mathematical operations like addition, subtraction,

                 multiplication, division, etc. These operators require two operands to operate. Following are
                 some of the binary operators.

                  Name of Operator         Symbol used       Purpose                           Example

                  Addition                 +                 Summation of Numbers              X=5+6 will yield 11

                  Subtraction              -                 Subtraction of Numbers            X=9-5 will yield 4

                  Multiplication           *                 Product of Numbers                X=3*4 will yield 12
                  Division                 /                 Division of Numbers               X=9/3 will yield 3.0

                  Modulus                  %                 Returns the remainder             X=5%2 will yield 1

                  Floor Division           //                Divides  and removes the  X=7//2 will yield 3
                                                             fractional part from result
                  Exponentiation           **                Returns  base  raised  to  the  X=3**3  will  yield

                                                             power of the exponent             27

                 2.5.2 Relational Operator

                 Relational operators are used to describe relationships between values or operands. In
                 Python, you will use six relational operators for comparing values. These operators are also
                 known as comparison operators.

                 The six relational operators are:

                  Operator                         Example (if a = 9, b = 5)         Result

                  >      Greater than              a>b                               True
                  <      Less than                 a<b                               False

                  >=    Greater than or equal to a>=b                                True

                  <=    Less than or  equal to     a<=b                              False
                  ==    Equal to                   a==b                              False

                  !=    Not equal to               a!=b                              True

                 You can conclude that the resultant of the comparison operator will be either True or False.



                                                                                       Python                       27
   24   25   26   27   28   29   30   31   32   33   34