The exercise to check if the book was on_shelf and not on_hold was failed with a response to not use “is” and “not” but to use “== True” instead. This response is wrong according to the Python Style Guide (PEP 8). Use of “If == True” when comparing boolean values is redundant and should be avoided.
Perhaps the grader or unittests expects it as ‘==’.
Hi @gawaasdorp,
The assignments test you with the material and coding concepts that are taught within the course. Yes, there can be multiple ways to implement the same logic, but if a particular thing is not covered in the course, for instance, as you pointed out, use of “is” and “not” keywords have not been discussed when it comes to comparing equality, then it is deemed incorrect in the scope of the assignment.
Hope this clears up the confusion.
Best,
Mubsi
Using == True
or == False
when checking boolean values is redundant and not recommended in idiomatic Python.
Example:
if book.on_shelf == True and book.on_hold == False:
# do something
This is technically valid Python but not idiomatic, and it reduces code clarity.
The correct approach:
Python encourages direct checks for boolean values.
Example:
if book.on_shelf and not book.on_hold:
# do something
This is clear, concise, and adheres to PEP 8:
Don’t compare boolean values to
True
orFalse
using==
.