- In python, we have the assignment operator
- Definition: The assignment operator is used to assigning a value to variables.
- eg:x=100
- Here we just assign a value of 100 to the x variable.
- we use the '"=" symbol to assign the values to the variables.
- After assigning the values to the variables it performs the different types of operations.
- The assignment operator mixed with another operator is called compound operator.
- The different types of compound operators are:
- +=
- -=
- *=
- /=
- %=
- //=
- **=
- &=
- |=
- ^=
- >>=
- <<=
Example: write a python program using assignmnet operators.
- x=5
- x+=5
- print(x)
- 10
- x=2
- x-=2
- print(x)
- 0
- x=2
- x*=12
- print(x)
- 144
- x=10
- x/=5
- print(x)
- 2.0
- a=4
- a%=2
- print(a)
- 0
No comments