PyPyPath

Module 3: Operators in Python

Assignment Operators

Assignment operators update a variable. = stores a value; shortcuts like += add and assign in one step.

About 8 minutes

The = operator

= is not “equals” in math — it means “put this value in the variable”.

Example code
points = 0
points = points + 10
print(points)  # 10

Shortcut operators

  • += add and assign
  • -= subtract and assign
  • *= multiply and assign
  • /= divide and assign
Example code
score = 50
score += 5   # same as score = score + 5
print(score)  # 55

score *= 2
print(score)  # 110
Practice

Start with savings = 100. Add 25, then multiply by 2. Print after each step.

Key takeaways

  • = assigns a value to a variable.
  • +=, -=, *=, /= update the variable in one line.
  • Shortcuts make code shorter and clearer.

Quick check: Assignment Operators

Question 1 of 2

After x = 5 and x += 2, what is x?