Page 74 - TP_Prime_V2.2_Class7
P. 74

Warm            State whether these  statements are True                 Century   #Information Literacy
                                                                                                   21 st
                       Up!             or False.                                                  Skills

                                       1.  Python does not follow the rules of operator precedence.
                                       2.  Python provides six types of relational operators.
                                       3.  Unary operator requires two operands.
           Prime (Ver. 2.2)-VII  Higher precedence operators are evaluated before the lower precedence operators. In                                                                                                                                    MORE ON PYTHON
                                       4.  "+" can also be used to concatenate two strings.






                  case of the same precedence, the associativity is used. Default associativity is Left to

                  Right. So, the first operator in the line will be evaluated first.


                                   Everyday, we face many situations where we need to make a decision. Can we
          72                                                                                                                                                                                                                                          73
                                  create programs in Python which involve decision making?

                                    Of  course,  we  can  create  this  type  of  programs  by  using  conditional
                                  statements. Let's learn about them.

                  In Python, conditional statements are used to control the transfer of the next sequence
                  to execute based on a specific conditional expression.
                  Similarly,  Python  program  can  have  conditions  and  make  decisions  based  on  those

                  conditions.

                    Conditional Statements

                  The concept of conditional statements in Python is very similar to conditions in real life.

                  When we face conditions in our everyday
                  life,  we  make  a  decision  based  on  them.

                  Similarly,  Python  program  can  have  If your age is not                      If your age is over 18,
                  conditions  and  decisions  based  on  those      over 18, then you are         you are eligible to vote.
                                                                    not eligible to vote.
                  conditions. Let’s take a simple example:

                  The first part of conditional statements is the condition itself. It is also the most important
                  part. Python interpreter will check the condition given and execute the next statement

                  based on that. There are three forms of conditional statements:
                    if Statement          if...else Statement        if…elif…else Statement


                    The if Statement
                  The if statement is the simplest conditional statement. Here, a statement or a collection

                  of statements within the if block is executed only if a certain condition or expression
   69   70   71   72   73   74   75   76   77   78   79