CMPT 120 Lecture 5: Week 4 Notes (Sept,28,30) (Oct,2)
meghan78 and 39786 others unlocked
29
CMPT 120 Full Course Notes
Verified Note
29 documents
Document Summary
Reassignment: a new assignment makes an existing variable refer to a new value (and stop referring to the old value). Ex. score = 75 score = 82 print(score) -> 82. One of the most common forms of reassignment is an update where the new value of the variable depends on the old. Ex. x = 1 print(x+1) -> 1 + 1 = 2. Updating a variable by adding 1 is called an increment; subtracting 1 is called a decrement. Sometimes programmers also talk about bumping a variable, which means the same as incrementing it by 1. Ex. print(int(3. 14)) -> 3 (removes all decimals) print (float(3. 14)) -> 3. 14 (keeps all decimals) print(type(float(3. 14))) -> print(str( 3. 14 )) -> 3. 1 (str removes the quotes) print(type(str(3. 14))) -> The range function: python gives us special built-in range objects that can deliver a sequence of values to the for loop.