Title: Assignment Operators
Slug: assignment_operators
Summary: Assignment Operators
Date: 2016-05-01 12:00
Category: Python
Tags: Basics
Authors: Chris Albon

Create some variables


In [41]:
a = 2
b = 1
c = 0
d = 3

Assigns values from right side to left side


In [42]:
c = a + b
c


Out[42]:
3

Add right to the left and assign the result to left (c = a + c)


In [43]:
c += a
c


Out[43]:
5

Subtract right from the left and assign the result to left (c = a - c)


In [44]:
c -= a
c


Out[44]:
3

Multiply right with the left and assign the result to left (c = a * c)


In [45]:
c *= a
c


Out[45]:
6

Divide left with the right and assign the result to left (c = c / a)


In [46]:
c /= a
c


Out[46]:
3.0

Takes modulus using two operands and assign the result to left (a = d % a)


In [47]:
d %= a
d


Out[47]:
1

Exponential (power) calculation on operators and assign value to the left (d = d ^ a)


In [48]:
d **= a
d


Out[48]:
1

Floor division on operators and assign value to the left (d = d // a)


In [24]:
d //= a
d


Out[24]:
0