Need help understanding this code
Posted: Sat Feb 16, 2019 11:27 pm
I'm trying to understand this code and what I don't understand is " if integer % 2:
Code: Select all
class EvenOnly(list): def append(self, integer): if not isinstance(integer, int): raise TypeError("Only integers can be added") if integer % 2: raise ValueError("Only even numbers can be added") super().append(integer) e = EvenOnly() e.append(2)
raise ValueError("Only even numbers can be added")"
If 2 % 2 which 2 is an even number shouldn't it raise an error since it is true?