- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Python Assignment Operators

Assume variable a holds 10 and variable b holds 20, then −

Sr.No | Operator & Description | Example |
---|---|---|

1 | =Assigns values from right side operands to left side operand | c = a + b assigns value of a + b into c |

2 | += Add ANDIt adds right operand to the left operand and assign the result to left operand | c += a is equivalent to c = c + a |

3 | -= Subtract ANDIf values of two operands are not equal, then condition becomes true.It subtracts right operand from the left operand and assign the result to left operand | c -= a is equivalent to c = c - a |

4 | *= Multiply ANDIt multiplies right operand with the left operand and assign the result to left operand | c *= a is equivalent to c = c * a |

5 | /= Divide ANDIt divides left operand with the right operand and assign the result to left operand | c /= a is equivalent to c = c / a |

6 | %= Modulus ANDIt takes modulus using two operands and assign the result to left operand | c %= a is equivalent to c = c % a |

7 | **= Exponent ANDPerforms exponential (power) calculation on operators and assign value to the left operand | c **= a is equivalent to c = c ** a |

8 | //= Floor DivisionIt performs floor division on operators and assign value to the left operand | c //= a is equivalent to c = c // a |

## Example

Assume variable a holds 10 and variable b holds 20, then −

#!/usr/bin/python a = 21 b = 10 c = 0 c = a + b print "Line 1 - Value of c is ", c c += a print "Line 2 - Value of c is ", c c *= a print "Line 3 - Value of c is ", 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 - Value of c is ", c

## Output

When you execute the above program it produces the following result −

Line 1 - Value of c is 31 Line 2 - Value of c is 52 Line 3 - Value of c is 1092 Line 4 - Value of c is 52 Line 5 - Value of c is 2 Line 6 - Value of c is 2097152 Line 7 - Value of c is 99864

- Related Questions & Answers
- Java Assignment Operators
- Perl Assignment Operators
- Assignment Operators in C++
- Compound assignment operators in C#
- Compound assignment operators in Java
- Compound Assignment Operators in C++
- Assignment operators in Dart Programming
- What are different assignment operators types in Python?
- What are assignment operators in C#?
- What are Assignment Operators in JavaScript?
- What are the assignment operators in Java?
- What is the difference between = and: = assignment operators?
- A += B Assignment Riddle in Python
- Python Arithmetic Operators
- Python Comparison Operators

Advertisements