Assignment operator in python part 19

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:


Assignment operator in python part   19

Post a Comment

0 Comments

Search This Blog