Page 92 - Digicode_AI_class_7
P. 92

Precedence of Operators

            Precedence of operators determines the order in which the operators are executed. The operator
            precedence in Python is listed in the following table. The highest precedence is at the top.

                     Operator                          Name
                     ( )                               Parenthesis

                     **                                Exponent

                     *, /, %, //                       Multiplication, Division, Modulo, Floor Division

                     +, –                              Addition, Subtraction

                     ==, !=, >, <, >=, <=              Comparison
                     =, +=, -=, *=, /=, %=, **=, //=   Assignment

                     and, or, not                      Logical






                     Arithmetic operators have higher precedence over Relational operators.


            There are situations in life when we need to decide based on a situation. For example, if it rains, I will
            stay at home or else I shall visit the market. Similar situations arise in programming as well, where we
            need to make some decisions and based on these decisions, execute a set of commands. We need to
            determine which action is to be taken and which statement is to be executed, if the outcome is true or
            false. In this chapter, we will learn about decision making statements of Python.
            Decision making in Python is done by called conditional statements which decide the flow of program
            execution. The following conditional statements are available in Python:

               if statement

               if...else statement

               Nested if statement
               if…elif…else ladder
                                                                                 Information Literacy
                   code Quest                                                    Technology Literacy


                 Define the following:

                 1.  Operators Precedence:

                 2.  Arithmetic Operators:
                 3.  Assignment Operators:







                90     DigiCode AI-VII
   87   88   89   90   91   92   93   94   95   96   97