Page 252 - COPA VOL II of II - TP -Punjabi
P. 252

ਟਾਸਕ 5 : ਅਸਾਈਨਮੈਂਟ ਆਪ੍ੇਟ੍ਹੇਠ ਲਭਖੇ ਅਨੁਸਾ੍ 1 ਅਸਾਈਨਮੈਂਟ ਆਪ੍ੇਟ੍
       1  Assignment opeartors as follows:                  print(b)
       # Examples of Assignment Operators                   # Subtract and assign value
       a = 10                                               b -= a
       # Assign value                                       print(b)
       b = a                                                # multiply and assign
       print(b)                                             b *= a

       # Add and assign value                               print(b)
       b += a                                               # bitwise lishift operator
       b <<= a                                              10
       print(b)                                             100
       Output:                                              102400
       10

       20


       ਟਾਸਕ 6 : ਆਪ੍ੇਟ੍ ਦੀ ਤ੍ਜੀਹ1 ਆਪ੍ੇਟ੍ ਦੀ ਤ੍ਜੀਹ ਹੇਠ ਲਭਖੇ ਅਨੁਸਾ੍ ਹੈ
       # Examples of Operator Precedence                    if  name  == “ Alex” o r  name  == “ John”  and  age > =  2:
                                                            print(“Hello! Welcome.”)
       # Precedence of ‘+’ & ‘*’
                                                            else:
       expr = 10 + 20 * 30
                                                            print(“Good Bye!!”)
       print(expr)
                                                            Output:
       # Precedence of ‘or’ & ‘and’
                                                            610
       name = “Alex”
                                                            Hello! Welcome.
       age = 0


       ਟਾਸਕ 7 : ਆਪ੍ੇਟ੍ ਐਸੋਸੀਏਸ਼ਨ1 ਆਪ੍ੇਟ੍ ਐਸੋਸਭਏਟੀਵਭਟੀ ਹੇਠ ਲਭਖੇ ਅਨੁਸਾ੍ ਹੈ
       # Examples of Operator Associativity                 # left-right associativity
       # Left-right associativity                           print(5 - (2 + 3))

       # 100 / 10 * 10 is calculated as                     # right-left associativity
       # (100 / 10) * 10 and not                            # 2 ** 3 ** 2 is calculated as
       # as 100 / (10 * 10)                                 # 2 ** (3 ** 2) and not
       print(100 / 10 * 10)                                 # as (2 ** 3) ** 2

       # Left-right associativity                           print(2 ** 3 ** 2)
       # 5 - 2 + 3 is calculated as                         Output
       # (5 - 2) + 3 and not                                100.0
       # as 5 - (2 + 3)                                     6
       print(5 - 2 + 3)                                     0














       238                       IT & ITES - COPA - (NSQF ਸੋਧੇ - 2022) - ਅਿਭਆਸ 1.39.05
   247   248   249   250   251   252   253   254   255   256   257