Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 90 - 2607_Trackpad_Pro_5.1_flipbook_C7
P. 90

    Operator        Name                 Description             Example (x=2)          Output

                                                      It returns true if both
                           and             AND                                       (x < 5) and (x < 10)      True
                                                      conditions are true.

                                                      It returns true if any one of
                            or              OR                                       (x < 5) or (x < 2)        True
                                                      the conditions 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.

                        Operator         Name                         Description                           Example

                                                       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  89

| 85 86 87 88 89 90 91 92 93 94 95 |