nick34992
5/8/2017 - 12:55 AM

Python: ClassName(list), isinstance(), TypeError, ValueError, .append()

Python: ClassName(list), isinstance(), TypeError, ValueError, .append()

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)