csev/py4e

Introduce basic assignment operators earlier in the book

doublewhy opened this issue · 1 comments

Hello Dr. Chuck!

Chapter 9.2 Dictionaries and files introduces basic assignment operators to a reader. Quote from the book:

In our else statement, we use the more compact alternative for incrementing a variable. counts[word] += 1 is equivalent to counts[word] = counts[word] + 1. Either method can be used to change the value of a variable by any desired amount. Similar alternatives exist for -=, *=, and /=.

My suggestion would be to introduce it much earlier, in Chapter 5.1 Updating variables. The motivation is that -=, *=, and /= operators are syntactic sugar for updating variables, the exact topic that is discussed in Chapter 5.1.

Thank you!

csev commented

Thanks for the suggestion. A big part of the pedagogy of this book is to delay any unnecessary concept until it is needed to keep from further confusing confused students. Your suggestion is perfect for someone who already knows coding - but if a student if struggling with a = a + 1 - then a += 1 will send them into a tail spin. The goal of the book is do just learn the minimum amount in each chapter to get through the chapter without quitting.