Page 196 - AI Ver 1.0 Class 10
P. 196

These operators with example are shown below:


                     Symbol                    Purpose                       Example                   Output
                       +=          Adds first and then assigns a new  N1=10
                                   value.                           N2=15

                                                                    N1+=N2

                                                                    N2+=5                               25 20
                                                                    print(N1,N2)

                       -=          Subtracts first and then assigns a  Num1=5
                                   new value.                       Num2=10


                                                                    Num2-=Num1
                                                                    print(Num2)                           5
                       *=          Multiplies first and then assigns  Prod=5
                                   a new value.                     Prod*=5

                                                                    print(Prod)                          25

                       /=          Divides  first  and  then  assigns  a  Value=25
                                   new value.                       Value/=5

                                                                    print(Value)                         5.0
                       //=         Floor  division  first  and  then  Value1=37
                                   assigns a new value.             print(Value1//5)                      7

                       %=          Remainder of a number first and  N1=39
                                   then assigns a new value.
                                                                    N2=5
                                                                    N1%=N2
                                                                    print(N1)                             4

                       **=         Exponential of a number first and  N1=2
                                   then assigns a new value.
                                                                    N2=4
                                                                    N1**=N2
                                                                    print(N1)                            16


              Operator Precedence
              An expression is made up of values, variables, operators and functions. For example:

              22/7*5.5 is an expression.
              To evaluate an expression with multiple operators we follow an order of precedence in Python. This order can be
              altered by writing an expression within parenthesis.









                        194   Touchpad Artificial Intelligence-X
   191   192   193   194   195   196   197   198   199   200   201