Assignment operator in python part 19
assignment operator
In Python, assignment operators are used to store data in a variable. We have already used the most common assignment operator (=), but there are many more of them:
= - Provides the value found in the right operand for the left operand. Example: x = 5
+ = - The value found in the left operand is called the value found in the right operand. Example: x = 5, x + = 3 results in x = 8.
- = - Subtracts the value of the right operand from the value found in the left operand. Example: x = 5, x - = 3 results in x = 2.
* = - Multiply the value of the right operand by the value of the left operand. Example: x = 5, x * = 3 results in x = 15.
/ = - Divides the value of the left operand by the value of the right operand. Example: x = 5, x / = 3 results in x = 1.667.
% = - divides the value found in the left operand by the value found in the right operand. The reminder will be placed in the left operand. Example: x = 5, x% = 3 results in x = 2.
** = - Determines the exponential value found in the left operand when raised to the power of the value in the right operand. Example: x = 5, x ** = 3 results in x = 125.
// = - Divides the value found in the left operand by the value of the right operand. The integer result will be placed in the left operand. Example: x = 5, x // = 3 results in x = 1.
Examples
Assuming the variable holds the value 10 and the variable b as 20, then -live demo
#! / Usr / bin / python
a = 21
B = 10
C = 0
C = a + b
Print "line 1 - c is value", c
C + = A
Print "line 2 - value of c", c
C * = a
Print "line 3 - c is value", c
C / = a
Print "line 4 - value of c is", c
C = 2
C% = a
Print "line 5 - value of c is", c
C ** = a
Print "line 6 - value of c is", c
C // = a
Print "line 7 - c is the value of", c
When you execute the above program, it produces the following result -
The value of row 1 - c is 31
The value of row 2 - c is 52.
The value of row 3 - c is 1092
The value of row 4 - c is 52.
The value of row 5 - c is 2
The value of line 6 - c is 2097152
The value of row 7 - c is 99864.
Suggested Link:
- Python Comment | Creating a Comment | multiline comment | example
- Python Comment | Creating a Comment | multiline comment | example
- Python Dictionary Introduction | Why to use dictionary | with example
- How to do Sum or Addition in python
- Python Reverse number
- find common number in python
- addition of number using for loop and providing user input data in python
- Python Count char in String
- Python Last Character from String
- Python Odd and Even | if condition
- Python Greater or equal number
- Python PALINDROME NUMBER
- Python FIBONACCI SERIES
- Python Dictionary | Items method | Definition and usage
- Python Dictionary | Add data , POP , popitem , update method
- Python Dictionary | update() method
- Delete statement , Looping in list In Python
- Odd and Even using Append in python
Assignment operator in python part 19
0 Comments