I am working my way through this code (thanks heaps CE!).
With regards to the following line of code in this exercise, I propose it should be changed, from (currently):
if not product in self.items_in_cart:
if product not in self.items_in_cart:
Two reasons I suggest this:
Firstly is that it is simply because I (as a novice programmer) had trouble deciphering what this line of code was actually doing when I first read it, as its written (as the first option) - so I rewrote it (as the second option) and the code still ran correctly, and I could understand it easier too.
Secondly, the second option seems to conform to the official Python specifications more closely.
e.g. from: https://www.python.org/dev/peps/pep-0008/
is not operator rather than
not ... is."
While both expressions are functionally identical, the former is more readable and preferred.
if foo is not None:
if not foo is None:
(I extrapolated this "not is" example to our "not in" example).
I understand the computer will (correctly) read them as being equal (due to operator implementation hierarchy) so its just a convention and human user friendliness that drives my suggestion.
I am interested to hear from any less novice programmers about this suggestion (and also more generally perhaps, outside of this specific example).
Once again; huge thanks to all for any help and suggestions.