Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 88 - 2607_Trackpad_Pro_5.1_flipbook_C7
P. 88

    Combination of variables, constants and operators makes an expression.

                                               Operator             Operator

                     Expression:       a           +          5         =         20

                                    Variable             Constants

                     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 right hand
                             –          Subtraction       operand from left hand          x – y                4
                                                          operand

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

                                                          Divides left hand
                              /         Division          operand by right hand           x / y             2.333333
                                                          operand

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

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

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

                                                                                        Tokens and Data Types in Python  87

| 83 84 85 86 87 88 89 90 91 92 93 |