Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 126 - 2609_Logiccode
P. 126

    On running the above program, you will get the following output:

                                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
                               ( )                               Parentheses

                               **                                Exponentiation
                               *, /, %, //                       Multiplication, Division, Modulus, Floor Division
                               +, –                              Addition, Subtraction

                               ==, !=, >, <, >=, <=              Comparison
                               =, +=, -=, *=, /=, %=, **=, //=   Assignment
                               not
                               or                                Logical
                               and

                           PURE
                           FACT        Arithmetic operators have higher precedence over Relational operators.

                                CONDITIONAL STATEMENTS

                      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.
                      Decision making in Python is done by conditional statements. Conditional statements allow a
                      program to make decisions and execute specific code blocks based on whether conditions are
                      True or False.

                      124   Premium Edition-VII

| 121 122 123 124 125 126 127 128 129 130 131 |