Cool Computer Science Thing of the Day
Reading Questions
Quiz
Assignment 2 Posted
Emacs Tip of the Day
- M-/ auto complete
Reusing Variables
Can assign a variable a value multiple times
x = 1 x = 2 print(x)
- Why do this?
Note, the order matters
Updating Variables
Can even update a variable using it’s own value
x = 1 x = x + 1 print(x)
- Can do this because of the order of operations
Assignment is always last, so can read value, compute new value, assign new value
Accumulating
- Updating variable values is most useful in a loops
For example computing the sum of a series
sum = 0 for i in range(10): sum = sum + 1 print(sum)