Page 139 - Trackpad_V1_Book 7_Flipbook
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, returns   not [(x < 5) and
                        not            NOT        false, if the result is true or   (x < 10)]             FALSE
                                                  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) calculation
                                  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