Page 21 - tp_Modula_v2.0
P. 21

OPERATORS

                 In Python, operators can be defined as special symbols which perform arithmetic and logical
                 computation.  The  values which  the  operators  use to  get  the  output  are  called  operands.

                 For example, in the expression 10 – 5, 10 and 5 are operands and the minus (–) sign is the
                 operator.

                 Python divides the operators in the following categories:

                 Arithmetic Operators

                 Arithmetic operators  perform arithmetic operations between  two operands.  The arithmetic
                 operators are defined in the following table:

                                                                                             Example
                  Operator        Name                        Description                    (x=7 and      Output

                                                                                               y=3)

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


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


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


                      /       Division          Divides left hand operand by right hand        x / y         2.33
                                                operand.


                      %       Modulus           Divides left hand operand by right             x % y          1
                                                hand operand and returns remainder.


                      **      Exponentiation Performs exponential (power)                      x ** y        343
                                                calculation on operands.


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
















                                                                            Data Types and Operators in Python    19
   16   17   18   19   20   21   22   23   24   25   26