Page 137 - Trackpad_V1_Book 7_Flipbook
P. 137

A combination of variables, constants and operators make an expression.


                                           Operator             Operator


                 Expression:       a           +          5         =         20




                                Variable              Constant


                 Now, learn about various types of operators.


                 Arithmetic Operators

                 These operators are used to do arithmetical operations.


                                                                                   Example
                     Operator           Name               Description           (x=7 and y=3)          Output



                                                      Adds values on either
                          +         Addition                                          x + y                10
                                                      side of the operator


                                                      Subtracts the right
                         –          Subtraction       hand operand from the           x – y                4
                                                      left hand operand

                                                      Multiplies values on
                         *          Multiplication    either side of the              x * y                21
                                                      operator

                                                      Divides the left hand
                          /         Division          operand by the right            x / y                3
                                                      hand operand

                                                      Divides the left hand
                                                      operand by the right
                         %          Modulus                                           x % y                 1
                                                      hand operand and

                                                      returns the remainder
                                                      Performs exponential
                         **         Exponentiation    (power) calculation on         x ** y               343
                                                      the operands


                                                      Divides and cuts the
                                    Floor or Integer
                         //                           fractional part from the        x // y               2
                                    division
                                                      result




                                                                                    Tokens and Data Types in Python  135
   132   133   134   135   136   137   138   139   140   141   142