#First we assign a value to a variable. x = 4 #Now we see that we can reuse it x y #Uh oh, looks like we didn't define our variable. #so we assign something to it. y = 15 + 8 y #What if we assign a variable a new value? x = 20 x #x now refers to the value 20 and not the value 4. #We can use more than one variable in an expression. y y = x - 2 y #So now y refers to a value that depends on the value that x referred to. #What if we change the value of x? x = 100 y #This means that when we assign y to refer to a value that depends on x, we don't tie the variables together, the value that y refers to depends only on the value that x referred to *at that point*. y = x + 2 y #What if we get y to refer to a value that depends on the value it refers to? #Like: draw on the board. #Does this even make sense? In math it doesn't. #But math equality is different then assignment. #Recall that assignment has two steps: First we evaluate the RHS, and then we assign that location to the LHS. #So what do we think will happen? y y = y + 1 y #now let's draw what happened on the board. #let's make sure we're clear on the distinction between evaluation and assignment. x x + 18 x x = x + 18 x #in the first case, we threw away the memory address of the value, but in the second case we kept it. #what if we're lazy? Can define multiple assignments at one. a, b= 9,17 a b #another distinction between math and assignment. sum = x + y sum #everything's fine. #in math, the following would mean the same thing as the assignment above. x+y = sum #but instead we get a giant mess. #back to slides.