Page 139 - Trackpad_V5_Book 7
P. 139

Operator         Name                Description              Example (x=2)         Output


                                             It returns true if both
                   and            AND                                       (x < 5) and (x < 10)      True
                                             operands are true.
                                             It returns true if one of the
                    or             OR                                       (x < 5) or (x < 2)        True
                                             operands is true.

                                             It reverses the result, and    not [(x < 5) and
                   not            NOT        returns false, if the result is   (x < 10)]              False
                                             true or vice versa.
            Assignment Operators

            These operators are used to assign value to a variable.

                                                                                                   Example
               Operator          Name                         Description                            (x=2)



                                              It assigns  the  value of the  operand  on the  right
                    =          Assignment                                                            x = 5
                                              side to the left side operand.

                                              It adds the  right  operand to  the  left operand
                                Addition
                   +=                         and assigns the result to the left operand. x+=3 is    x += 3
                               assignment
                                              equivalent to x=x+3.
                                              It subtracts the right operand from the left operand
                               Subtraction
                   –=                         and assigns the result to the left operand. x–=3 is    x –= 3
                               assignment
                                              equivalent to x=x–3.

                                              It multiplies the right operand with the left operand
                              Multiplication
                   *=                         and assigns the result to the left operand. x*=3 is    x *= 3
                               assignment
                                              equivalent to x=x*3.

                                              It divides the left operand with the right operand
                                 Division
                   /=                         and assigns the result to the left operand. x/=3 is    x /= 3
                               assignment
                                              equivalent to x=x/3.

                               Remainder      It takes the modulus of two operands and assigns the
                   %=                                                                                x %= 3
                               assignment     result to the left operand. x%=3 is equivalent to x=x%3.
                                              It performs floor division on operators and assigns
                              Floor division
                   //=                        the value to the left operand. x//=3 is equivalent to   x //= 3
                               assignment
                                              x=x//3.
                                              It performs exponential  (power) calculations
                             Exponentiation
                  **=                         on operators and assigns the value to  the left       x **= 3
                               assignment
                                              operand. x**=3 is equivalent to x=x**3.


                                                                               Tokens and Data Types in Python  137
   134   135   136   137   138   139   140   141   142   143   144