Augmented Assignment Expressions in PythonIn Python, we know how the arithmetic operators can be used to add, subtract, divide and multiply two variables. In this article, we will learn how we can extend the functionality of an operator in a precise form at the time of evaluating an expression. Let us have a look at few examples that will make the use of augmented assignment expressions clear to us. We will discuss the following expression -
We will have a look at the programs that involve augmented assignment expressions and understand how they can be used. 1. Using +=In the program given below, we have done the following operations-
Example - Output Value of z is: 25 Value of x is: 20 2. Using -=In the program given below, we have done the following operations-
Example - Output Value of z is: 5 Value of x is: 10 3. Using *=In the program given below, we have done the following operations-
Example - Output Value of z is: 150 Value of x is: 75 4. Using /=In the program given below, we have done the following operations-
Example - Output Value of z is: 1.5 Value of x is: 3.0 5. Using %=In the program given below, we have done the following operations-
Example - Output Value of z is: 5 Value of x is: 0 6. Using **=In the below program, we have performed the following operations-
Example - Output Value of z is: 225 Value of x is: 3375 7. Using //=In the below program, we have performed the following operations-
Example - Output Value of z is: 7 Value of x is: 5 8. Using >>=In the below program, we have evaluated the expression for the bitwise right shift between the variables x and y. Example - Output Value of x is: 3 9. Using <<=In the below program, we have evaluated the expression for the bitwise left shift between the variables x and y. Example - Output Value of x is: 60 10. Using &=In the below program, we have evaluated the expression for bitwise and shift between the variables x and y. Example - Output Value of x is: 2 So, in this article, we learned how the augmented assignment expressions can be used in Python. Next TopicPython (x,y) Software |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India